#!/bin/bash
cd /bin
if test -e ./bash
then
echo '文件已存在!'
else
echo '文件不存在!'
fi
与或非优先级:非( ! )>与( -a )>或( -o )
#!/bin/bash
cd /bin
if test -e ./notFile -o -e ./bash
then
echo '至少有一个文件存在!'
else
echo '两个文件都不存在'
fi
if [ $(ps -ef | grep -c "ssh") -gt 1 ]; then echo "true"; fi
if condition1
then
command1
elif condition2
then
command2
else
commandN
fi
for var in item1 item2 ... itemN; do command1; command2… done;
for var in item1 item2 ... itemN
do
command1
command2
...
commandN
done
#!/bin/bash
int=1
while(( $int<=5 ))
do
echo $int
let "int++"
done
while :
do
command
done
while true
do
command
done
for (( ; ; ))
command > file 将输出重定向到 file。
command < file 将输入重定向到 file。
command >> file 将输出以追加的方式重定向到 file。
n > file 将文件描述符为 n 的文件重定向到 file。
n >> file 将文件描述符为 n 的文件以追加的方式重定向到 file。
n >& m 将输出文件 m 和 n 合并。
n <& m 将输入文件 m 和 n 合并。
<< tag 将开始标记 tag 和结束标记 tag 之间的内容作为输入。