Bash编程入门(三)
Shell编程很有趣,Shell编程很复杂,Shell编程离我们很近又似乎很远:使用Linux离不开它,但似乎又不曾仔细了解它。这套文章的目的是带你走进Shell编程的大门 ,领略它的丰富多彩。
* 本节讲解内容:括号
* 本节使用的shell版本为:
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin11)Copyright (C) 2007 Free Software Foundation, Inc.
$ <some_command><output result>
$ echo $(pwd)/Users/liweinan
$ echo `pwd`/Users/liweinan
$ echo $(ls $(pwd))Desktop Documents Downloads Games Library Movies Music Pictures Public Sites
name=abcprintf "name is %s\n" $name
name is abc
(name=abc)printf "name is %s\n" $name
name is
ls -1 Xee.[jp][pn]gXee.jngXee.jpgXee.pngXee.ppg
str=aif [ -n $str ]; thenecho "str exists"elseecho "str not exists"fi
str exists
[ -z $str ]
[ $str1 = $str2 ]
str1=astr2=bif [ str1=str2 ]; thenecho "str1=str2"fiif [ $str1=$str2 ]; thenecho "$str1=$str2"fiif [ $str1 = $str2 ]; thenecho "$str1 = $str2"fi
str1=str2a=b
if [ str1=str2 ]; thenecho "str1=str2"fi
...if [ $str1=$str2 ]; then...if [ $str1 = $str2 ]; then...
{printf aprintf bprintf c} > abc$ cat abcabc
{ while read line; do echo $line done} < abc$ echo {a,b,c}a b c$ echo {1..3}1 2 3