Home

ShellScript(6) - case

case 문을 알아보겠습니다. 기본문법 1 2 3 4 case word in pattern) command ;; esac 예제.1 1 2 3 4 5 6 7 8 9 10 11 12 13 #!/bin/bash echo "Enter your lucky number" read n case $n in 101) echo echo "You got 1st prize" ;; 510) echo "You got 2nd prize" ;; 999) echo "You got 3rd prize" ;; *) echo "Sorry, try for the next time" ;; esac ...

Read more

ShellScript(5) - if, and, or

if 문의 몇가지 예제를 통해 사용방법을 알아보도록 하겠습니다. 연산자 의미 x -eq y x가 y와 같은지 체크 x -ne y x가 y와 같지 않은지 체크 x -lt y x가 y 보다 작은지 체크 x -le y x가 y 보다 작거나 같은지 체크 x -gt y x가 y 보다 큰지 체크 x -ge y x가 y 보다 크거나 같은지 ...

Read more

ShellScript(4) - read

read 를 사용하여 사용자가 입력을 할 수 있습니다. 예제.1 - Using simple read command 1 2 3 4 #!/bin/bash echo -n "What is your favorite food : " read answer echo "Oh! you like $answer!" apple 을 입력해 보겠습니다. What is your favorite food : apple Oh! you like apple! 예제.2 - Using read command with options -p 옵션은 입력을 위한 prompt를 활성화 시킵니다. -s 옵션은 Secret mode...

Read more

ShellScript(3) - while, for

반복문 while, for 의 문법을 살펴보겠습니다. 1. 반복문 while (Using While Loop) 문법 condition(조건식)에 따라 do 와 done 사이의 commands(명령)을 반복합니다. 1 2 3 4 5 #!/bin/bash while [ condition ] do commands done 예제.1 n이 1보다 작거나 같으면 true가되어 do 와 done 사이의 명령을 반복 실행합니다. 1 2 3 4 5 6 7 #!/bin/bash n=1 while [ $n -le 5 ] do echo "Running $n time" (...

Read more

ShellScript(2) - echo , 주석처리

출처 : https://linuxhint.com/30_bash_script_examples/ 리눅스 쉘스크립트예제를 통해서 기본적인 문법을 익혀보도록 하겠습니다. 저는 vim을 사용했지만, 각자 기호에 맞는 에디터를 사용하시면 됩니다. 화면출력(echo)와 주석처리에 대해 살펴보겠습니다. 1. ShellScript 생성 및 실행 echo 명령으로 Hello World 를 출력해 봅시다. $ vi first.sh 1 2 #!/bin/bash echo "Hello World" 만들어진 shell 파일을 실행해 봅시다. $ sh first.sh 또는 .sh 파일에 실행...

Read more

ShellScript(1) - 연산자

Linux Shell Script의 기본적인 내용을 정리합니다. 1. 파일관련연산 파일관련연산자 의미 -d 파일이 디렉토리인지 체크 -e 파일이 존재하는지 체크 -a 파일이 존재하는지 체크 -r 파일이 읽기 가능인지 체크 -w 파일이 쓰기 가능인지 체크 -x 파일이 실행 가능인지 체크 -o ...

Read more

Linux Shell Prompt 글자속성 변경 및 색상지정

Linux Shell-Prompt를 자신이 원하는 셋팅을 하여 가독성을 높일 수 있습니다. 기호에 맞게 바꿔서 사용해보세요. 1. Text Attributes ANSI CODE Meaning 0 Normal Characters 1 Bold Characters 4 Underlined Characters 5 Blinking Characters 7 Reverse vide...

Read more