Unix script 15 - quick reference

来源:互联网 发布:c语言如何输入n个数 编辑:程序博客网 时间:2024/06/03 19:13
This is a quick reference guide to the meaning of some of the less easilyguessed commands and codes.CommandDescriptionExample&Run the previous command in the backgroundls &&&Logical ANDif [ "$foo" -ge "0" ] && [ "$foo" -le "9"]||Logical ORif [ "$foo" -lt "0" ] || [ "$foo" -gt "9" ] (not in Bourne shell)^Start of linegrep "^foo"$End of linegrep "foo$"=String equality (cf. -eq)if [ "$foo" = "bar" ]!Logical NOTif [ "$foo" != "bar" ]$$PID of current shellecho "my PID = $$"$!PID of last background commandls & echo "PID of ls = $!"$?exit status of last commandls ; echo "ls returned code $?"$0Name of current command (as called)echo "I am $0"$1Name of current command's first parameterecho "My first argument is $1"$9Name of current command's ninth parameterecho "My ninth argument is $9"$@All of current command's parameters (preserving whitespace and quoting)echo "My arguments are $@"$*All of current command's parameters (not preserving whitespace and quoting)echo "My arguments are $*"-eqNumeric Equalityif [ "$foo" -eq "9" ]-neNumeric Inqualityif [ "$foo" -ne "9" ]-ltLess Thanif [ "$foo" -lt "9" ]-leLess Than or Equalif [ "$foo" -le "9" ]-gtGreater Thanif [ "$foo" -gt "9" ]-geGreater Than or Equalif [ "$foo" -ge "9" ]-zString is zero lengthif [ -z "$foo" ]-nString is not zero lengthif [ -n "$foo" ]-ntNewer Thanif [ "$file1" -nt "$file2" ]-dIs a Directoryif [ -d /bin ]-fIs a Fileif [ -f /bin/ls ]-rIs a readable fileif [ -r /bin/ls ]-wIs a writable fileif [ -w /bin/ls ]-xIs an executable fileif [ -x /bin/ls ]parenthesis:
( ... )Function definitionfunction myfunc() { echo hello }
原创粉丝点击