test expression
[ expression ]
Compound Command는 예약어로 시작되고 그에 상응하는 예약어로 종료된다.
Single-line
Multi-line
커맨드라인은
NEWLINE
,;
,&
으로 종료된다.
#! /bin/bash
if [ $# -lt 2 ]
then
echo "usage: $0 file1 file2"
exit 1
fi
echo "program start"
exit 0
$ ./ifex.sh a
usage: ./ifex.sh file1 file2
$ ./ifex.sh a b
program start
#! /bin/bash
echo -n "Enter your password: "
read password
if [ $password ="secret" ]
then
echo "Welcome!"
else
echo "Try again!"
fi
$ ./ifex.sh
Enter your password: secret
"Welcome!"
$ ./ifex.sh
Enter your password: secre
Try again!
#! /bin/bash
if [ $# -ne 1]
then
echo "usage: $0 file"
exit 1
fi
file=$1
if [ -f "$file" ]; then
echo "$file is a file"
else
if [ -d "$file" ]; then
echo "$file is a directory"
fi
fi
exit 0
$ ls
a b
$ ./ifex.sh
usage: ./ifex.sh file
$ ./ifex.sh a
a is a file
$ ./ifex.sh b
b is a directory
$ ./ifex.sh c