ShellScript
Basic script
#!/bin/sh
# comment
# command
echo "ShellScript"
Exit
# 스크립트 종료
exit
# 스크립트 종료, 종료 상태 반환
# exit state
exit 1
Shellcheck
sudo apt install -y shellcheck
Variables
# str1 = hello 안됨
str1=hello
# str2=hello world 안됨
str2="hello world"
# 숫자도 문자열로 저장됨
str3=100
# 상수
readonly STR4="CONST"
# 환경 변수
export STR5="ENV"
echo $str1
# echo $str2!! 안됨
echo ${str2}!!
위험
ShellScript는 공백 사용에 주의해야 합니다.
Reserved Variable
- $HOME: 사용자 홈 디렉터리
- $PATH: 실행 파일 경로
- $EUID: Effective User ID
Commands
터미널에서 사용하던 커맨드를 모두 사용할 수 있습니다.
# commands
ls /dev/i2c*
echo "hi"
stdout=$(command)
Functions
sample_func() {
    # parameter 1, 2 ,3 번
    echo $1 $2 $3 ...
    global_var=1
    local local_var=1
    return 1
}
sample_func arg1 arg2 arg3 ...
# return -> $?
echo $?