shell語句總結:php
1.開頭必須的java
#!/bin/sh
2.echo 輸出結果python
3.if語句linux
if[ -d $1] then echo "this is a directoty!" elif [ -f $1 ] then echo "is a file!" else echo "this a ..." fi
4.for 語句c++
for var in 1 2 3 4 5 6 7 8 9 10 do echo "number is $var" done
5.select語句shell
select var in "java" "c++" "php" "linux" "python" "ruby" "c#" do break done echo "you selected $var"
6.case語句c#
#!/bin/sh read op case $op in a) echo "you selected a";; b) echo "you selected b";; c) echo "you selected c";; *) echo "error" esac
7.while語句ruby
#!/bin/sh num=1 sum=0 while [ $num -le 100 ] do sum=`expr $sum + $num` num=`expr $num + 1` done echo $sum
8.while語句與if語句相結合bash
#!/bin/sh i=0 while [ $i -le 100 ] do i=`expr $i + 1` if [ $i -eq 5 -o $i -eq 10 ] then continue; else echo "this number is $i" fi if [ $i -eq 15 ] then break; fi done