Check if string is null or empty in Bash
External file or output of command in Terminal
Code command lines in Bash Script to order what computer should do in Terminal
맨 윗 줄엔 항상 #!/bin/bash 를 적어 준다. 빠트리거나 스펠링을 틀리게 적으면 명령어를 이용해 작업할 때 원할하지 않음
위와 같이 $filename으로 얻을 value와 비교할 대상 (source/secretinfo.md)가 모두 string이면 quotation mark가 필요함
if condition 두개가 or operator로 연결되어 있다.
-z옵션을 이용하면 length of the variable이 zero인지 아닌지 확인 가능. zero면 true.
#!/bin/bash를 적어 준다. ( 컴퓨터에서 해당 file이 bash script임을 알리는 역할)chmod +x script.sh를 작성하고 permission을 획득할 수 있다.
터미널에서 ./myscript.sh로 bash file을 실행하였으나 permission denied 됨. 이후, chmod +x [파일명]으로 permission 획득.
왼쪽이 bash script / 오른쪽이 terminal
lt는 less than이라는 의미
snippet에서는 나와 있지 않지만 if문 밖에 "index" variable을 assign하였음
greeting_occasion의 value값에 따라 다르게 if절이 적용.
greeting_occasion의 value가 0이므로 if절의 조건과 만난다. 따라서, terminal에 value of first_greeting variable 가 print
if와 else 이외의 다른 conditional이 존재하는 경우
dollor sign ( $ )는 value를 access할 때만 필요함
for loop은 list 안의 data를 iterator할 때 유용 ( ex) array)
bash script에선 arithmetic은 $((...)) syntax 안에서만 가능함
하이라이트 표시 부분이 stopping point
위의 식에서는 if 조건문이 do 와 done 사이에 위치함
read variable

in terminal
.bashrc나 .bash_profile 안에 지정
standard input arguments 중에 하나인 green을 saycolors bash파일의 첫 input으로 지정하고 싶다면 위와 같은 방법 사용??
왼쪽이 input in a bash script / 오른쪽이 output in terminal
-n 1 의 의미 : changelog.md에 있는 line 중 첫번째 한 줄만 return
왼쪽이 input in a bash script / 오른쪽이 output in terminal
왼쪽은 input in a bash script / 오른쪽은 output in terminal
마크 된 line의 의미는 variable_firstline의 value값은 splitfirstline이라는 read -a를 통해 생성된 array에 나누어 redirect한다는 내용.
variable_firstline의 value는 ## 11.2.3이였고 ##과 11.2.3가 나뉘어 array에 저장되었었음.
따라서, splitfirstline[1]를 print하면 output으론 11.2.3만 print
왼쪽이 bash script / 오른쪽이 terminal
흰색으로 mark된 부분이 ㅠash script 안의 명령 command lines. 오른쪽 파란색 mark에 해당 code output을 확인할 수 있다
Input arguments can be passed to a bash script after the script name, separated by spaces ( myScript.sh "hello" "how are you") 안됨 ㅡㅡ bash script에 먼가 argument의 쌍인 parameter가 들어가야 할 것 같은데 ㅡㅡ ?