[root@localhost temp]# cat a.sh #!/bin/bash #hello echo '你好' echo 'Hello World!' [root@localhost temp]# ./a.sh 你好 Hello World! [root@localhost temp]# cat b.sh #!/bin/bash #bianliang b.sh a=123 b=1.23 c=xyz d=efgh xyz e='efgh xyz' echo $a echo $b echo $c echo $d echo $e [root@localhost temp]# ./b.sh ./b.sh: line 6: xyz: command not found 123 1.23 xyz efgh xyz [root@localhost temp]# cat c.sh #!/bin/bash #c.sh echo $1 echo $2 echo $3 echo $4 [root@localhost temp]# ./c.sh a b c d e a b c d [root@localhost temp]# cat e.sh #!/bin/bash #e.sh echo 开始 read a i=$[ $a % 2 ] echo -e $a"\c" if test $i -eq 0 then echo 是偶数 else echo 是奇数 fi echo 结束 [root@localhost temp]# ./e.sh 开始 3 3是奇数 结束 [root@localhost temp]# cat f.sh #!/bin/bash #e.sh echo 开始 i=$[ $1 % 2 ] echo -e $1"\c" if test $i -eq 0 then echo 是偶数 else echo 是奇数 fi echo 结束 [root@localhost temp]# ./f.sh 8 开始 8是偶数 结束 [root@localhost temp]# cat g.sh #!/bin/bash #g.sh if test -z $1 then echo "请输入一个文件名" else if test -w $1 then echo "可写" else echo "不可写" fi if test -x $1 then echo "可执行" else echo "不可执行" fi if test -z $2 then echo "参数2要输入" elif test $2 -eq 1 then echo "输入1" elif test $2 -eq 2 then echo "输入2" else echo "输入"$2 fi fi [root@localhost temp]# ./g.sh a.sh 2 可写 可执行 输入2 [root@localhost temp]# cat h.sh #!/bin/bash #h.sh for char in a b c d e do echo $char done for str do echo $str done [root@localhost temp]# ./h.sh a b c d e [root@localhost temp]# cat i.sh #!/bin/bash #i.sh files=`ls *.sh` for sh in $files do txt=`echo $sh | sed "s/.sh/.txt/"` cp $sh $txt echo $txt done [root@localhost temp]# ./i.sh a.txt b.txt c.txt d.txt e.txt f.txt g.txt h.txt i.txt j.txt k.txt [root@localhost temp]# cat j.sh #!/bin/bash #j.sh for i in 1 2 3 4 5 6 7 8 9 do for j in 1 2 3 4 5 6 7 8 9 do if test $i -ge $j then echo -e $j \* $i = $[ $j * $i ]" \c" fi done echo "" done [root@localhost temp]# ./j.sh 1 * 1 = 1 1 * 2 = 2 2 * 2 = 4 1 * 3 = 3 2 * 3 = 6 3 * 3 = 9 1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16 1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5 = 25 1 * 6 = 6 2 * 6 = 12 3 * 6 = 18 4 * 6 = 24 5 * 6 = 30 6 * 6 = 36 1 * 7 = 7 2 * 7 = 14 3 * 7 = 21 4 * 7 = 28 5 * 7 = 35 6 * 7 = 42 7 * 7 = 49 1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81 [root@localhost temp]# cat k.sh #!/bin/bash #k.sh echo -e "请输入一个1-100之间的整数:\c" flag=0 until [ $flag -eq 1 ] do read num expr $num "+" 10 &> /dev/null if test $? -ne 0 then echo -e $num"不是整数,请重新输入:\c" else if test $num -ge 1 -a $num -le 100 then flag=1 else echo -e $num"不在1-100之间,请重新输入:\c" fi fi done sum=0 i=1 until test $i -gt $num do sum=$[$sum+$i] i=$[$i+1] done echo "" echo "从1到"$num"的总和为:"$sum [root@localhost temp]# ./k.sh 请输入一个1-100之间的整数:a a不是整数,请重新输入:0 0不在1-100之间,请重新输入:101 101不在1-100之间,请重新输入:100.01 100.01不是整数,请重新输入:20 从1到20的总和为:210 [root@localhost temp]#
相关推荐
linux_shell编程入门书籍,配合实例讲解,有助于新手入门,欢迎下载
Linux_Shell实例精解 Linux_Shell实例精解.rar总页数:540多页,很全的
Linux Shell实例精讲,大量实例shell,容易理解和实践
Linux Shell 实例精解 (pdf 版本)
LinuxShell脚本编程实例.doc
LinuxShell脚本编程实例.pdf
Linux Shell 实例精解Linux Shell 实例精解
Linux.Shell.Linux.Shell.实例Linux.Shell.实例精解精解实例精解Linux.Shell.实例精解
linux Shell编程入门 实例讲解详解.doc
linux操作实例,很实用的操作指令,有助于学习linux。
linux Shell编程入门 实例讲解详解
Linux Shell 实例精解4 (pdf 版本)
Linux shell编程实例精解, 本书重点讲述了当下最流行的两个Linux Shell——Borne Again Shell (bash)和TC Shell(tcsh),从它们的新特性、增加和内建的插件讲起直至具体的应用。通过对一个个实例的讲解,循序渐进地...
Linux下Shell编程实例,gooooooooooooooooooooood!
Linux的学习和应用..................................................
Linux Shell 实例精解Linux Shell 实例精解
通过对一个个实例的讲解,循序渐进地介绍了Linux Shell中的各个知识点,使读者逐步具备读写Shell程序的能力。 注:之前上传一个附件有误,这个为正确的。有两个压缩包,两个都下好了再解压即可。打开文档如果有乱码...
linux shell 编程实例开发 书的影印版