动态倒计时:
#!/bin/bash
tput sc
count=20;
while true;
do
    if [ $count -gt 0 ];
    then
        let count--;
        sleep 1;
        tput rc
        tput ed
        echo -n $count;
    else
        exit 0;
    fi
done

在shell脚本中把命令行输入的所有参数组装成命令运行

#!/bin/bash
if [ $a -eq 1 ];then
    :
else
   $@
fi


shell脚本里的子进程:用()把代码段括起来

读取三个字符存到变量val (不用按回车)
read -n 3 val

生成序列:
echo {1..50}

录制脚本:
script -t 2> timing.log -a output.session
命令1;
命令2;
…
..
exit

回放:
scriptreplay timing.log output.session


find . \( -name "*.txt" -o -name "*.pdf" \) -print


${VAR%.*} 的含义如下所述:
 从 $VAR中删除位于 % 右侧的通配符(在前例中是.*)所匹配的字符串。通配符从右向左
进行匹配。
 给VAR赋值,VAR=sample.jpg。那么,通配符从右向左就会匹配到.jpg,因此,从 $VAR
中删除匹配结果,就会得到输出sample。
file_jpg="sample.jpg"
name=${file_jpg%.*}
echo File name is: $name
输出结果:
File name is: sample

%属于非贪婪匹配,%%则是贪婪的


#!/bin/bash
#文件名: interactive.sh
read -p "Enter number:" no ;
read -p "Enter name:" name
echo You have entered $no, $name;
非交互输入:
$ echo -e "1\nhello\n" | ./interactive.sh
或者:
echo -e "1\nhello\n" > input.data
./interactive.sh < input.data


有任何疑问请点击留言: 留言板
本文发布于http://wiki.too2.net,转载请联系本人。