$# 가 스크립트의 인자 갯수를 가진 변수이다.if [ "$#" -ne 2 ]; then
echo "인자 2개를 넘겨주어야 합니다."
fi
source /dev/stdin 으로 해주면 된다.ls | sed ... | source /dev/stdin
cat <<EOF >/home/a.config first line second line third line EOF
find . -type f |
while read -r line
do
echo "$line"
done
# one liner
find . -type f | while read -r line; do echo "$line"; done
# 혹은
while read -r line
do
echo "$line"
done < <(find . -type f)
명령 || 다른 명령 을 하면 첫번째 명령이 성공하면 그대로 넘어가고 실패했을 경우에는 다른 명령을 실행하고 그 결과를 최종 반환한다.# curl 명령 실패시에 "{}" 를 변수에 값으로 저장
TEST_RESULT=$(curl -Ss https://.... || echo "{}")
command : POSIX 호환. 정확히는 명령에 대해 설명을 출력하는 것임. alias, function 등도 체크함.command -v <원하는명령>
if ! command -v <the_command> &> /dev/null
then
echo "<the_command> could not be found"
exit
fi
hash <명령> : 일반적인 명령 검사. alias, function 도 존재여부 exit code로 확인가능. 명령이 존재하면 exit code 0이고 아니면 오류 메시지. 따라서 error stream 처리(2>/dev/null)이 필요하다.type <명령> : shell 내장 명령 혹은 keyword 검사. 설명 메시지 혹은 존재하지 않는 명령이면 오류메시지. &>/dev/null stream 처리 필요.if hash gdate 2>/dev/null; then
gdate "$@"
else
date "$@"
fi