bash 6

bash shell looping (반복문)

[목차] 1. 산술연상 expr, let 2. while and until loop 3. for-loop 1. 산술연상 expr, let expr - 정수형 산술연산(+,-,*,/,%), 논리연산(|,&), 관계연상(=,!=,>,>=, /dev/null echo $? # 2 cat > newuser #!/bin/bash #Description: Create a user account. echo -n "New username: " read username while getent passwd $username &> /dev/null do echo "Sorry, that account $username is already taken. Please pick a different username." echo -n..

개발/Linux 2023.01.02

bash shell branching (조건문)

[목차] 1. exit 2. test 3. if-then-fi 4. case 1. exit - 실행된 프로그램이 종료된 상태를 전달 exit 0 프로그램 또는 명령이 성공으올 종료했음을 의미 1-255 프로그램 또는 명령이 실패로 종료했음을 의미 ( 1 일반 에러 2 Syntax Error 126 명령을 실행할 수 없음 127 명령 (파일) 이 존재하지 않음 128+N 종료 시그널+N (kill -9 PID 로 종료 시 128+9=137) $? 종료 값 출력 cp file1 echo $? # 1 sleep 100 echo $? # 130 : 128 + 2(KILL:SIGINT) kill -l 2. test - 비교연산자 test or [ 명령어 ] - 명령어 실행결과를 true(0) 또는 false(1)..

개발/Linux 2023.01.02

Bash Shell 입출력 (echo, read, printf)

[목차] 1. echo 2. read 3. printf 1. echo prints text to standard output echo -n : 메시지 출력 후 newline 문자를 추가하지 않는다. -e : backslash escapes문자를 해석하여 특별한 의미를 지정한다. \t : TAB키 \n: 줄 바꿈 \a: alert(bell) - 예시 echo "Your time is up" echo "Your time is up" > time.txt echo -n "Name:" echo -e "First\tSecond" score=90 echo score # score echo $score # 90 2. read reads text from standard input read 변수명 -n : 지정한 문자수..

개발/Linux 2023.01.02

Bash Shell Positional Parameters (위치 매개변수)

- 위치 매개변수 - 입력하는 argument들은 $0, $1, $2와 같은 변수에 저장되어 script에 전달 - 10번째 argument 부터는 ${10} 처럼 중괄호를 사용 name of shell script : $0 first argument : $1 second argument : $2 Number of arguments in $# List of all parameters in $@, $* - Special shell variables 로그인 shell의 PID : $$ 현재 작업 디렉토리 : $PWD 부모 프로세스 ID : $PPID # passwd 파일을 현재 위치의 pass 파일로 복사하는 명령어 # $0 $1 $2 cp /etc/passwd ./pass cat > parameter-ex..

개발/Linux 2023.01.02

Bash shell과 Rules(기능)

[목차] 1. Quoting Rule 2. Nesting commands 3. Alias 4. Prompt 5. Redirection 6. Pipeline 1. Quoting Rule Metacharacters - Shell에서 특별히 의미를 정해 놓은 문자들 - ₩ ? () $ ... * % {} [] 등 # 예시) 현재 위치에서 # 모든 파일 조회 echo * # a로 시작하는 모든 파일 조회 echo a* # ?는 Any Single Character. 4개의 문자수를 가진 파일 조회 echo ???? # {숫자1..숫자3}은 숫자1부터 숫자3까지를 뜻함 touch myfile{1..3} Quoting Rule : 메타문자의 의미를 제거하고 단순 문자로 변경 - Backslash(\) : \ 바로 ..

개발/Linux 2022.12.30

Linux Shell이란, Bash shell과 변수

[목차] 1. Shell의 역할 2. Shell의 종류 3. 기본 Shell 구성하기 4. Shell의 변수 5. Shell의 환경변수 1. Shell의 역할 Shell은 사용자 명령어 해석기 사용자가 프롬프트에 입력한 명령을 해석해서 운영체제에게 전달 2. Shell의 종류 Bourne shell(sh) AT&T 벨 연구소의 스티븐 본(Stephen Bourne)이 개발한 Original shell C Shell(csh,tcsh) Bill Joy 가 C언어의 기술을 넣어서 만든 Shell C언어의 문법을 적용 History, aliases, job control, vi command editing and completion 기능을 포함 Korn Shell(ksh) David Korn이 AT&T에서 기존..

개발/Linux 2022.12.30
728x90
반응형