分类: LINUX
2009-03-23 11:26:48
[root@redhat ~]# winner=bob
[root@redhat ~]# notice="the person who won is $winner" [root@redhat ~]# echo $notice the person who won is bob ##将$winner解析成变量 |
[root@redhat ~]# winner=bob
[root@redhat ~]# notice='the person who won is $winner' [root@redhat ~]# echo $notice the person who won is $winner ##$winner只是符号 [root@redhat ~]# echo $winner bob |
[root@redhat ~]# winner=bob
[root@redhat ~]# notice="the person who won is \$winner" [root@redhat ~]# echo $notice the person who won is $winner ##用\将$转义成字符 [root@redhat ~]# echo $winner bob |
[root@redhat ~]# listnew='ls *.new'
[root@redhat ~]# echo $listnew ls main.cf.new master.cf.new ##仔细查看,两个结果不一样的 |
[root@redhat ~]# listnew=`ls *.new`
[root@redhat ~]# echo $listnew main.cf.new master.cf.new |
[root@redhat ~]# let a=2*7
[root@redhat ~]# echo $a 14 [root@redhat ~]# let a="2 * 7" [root@redhat ~]# echo $a 14 |
[root@redhat ~]# num=5
[root@redhat ~]# test $num -eq 10 [root@redhat ~]# echo $? 1 ##返回比较的结果值 [root@redhat ~]# num=5 [root@redhat ~]# test $num -eq 5 [root@redhat ~]# echo $? 0 |
[root@redhat ~]# num=5
[root@redhat ~]# [ $num -eq 10 ] ##注意中间空格的地方 [root@redhat ~]# echo $? 1 [root@redhat ~]# num=5 [root@redhat ~]# [ $num -eq 5 ] [root@redhat ~]# echo $? 0 |
[root@redhat ~]# vi lss.sh
#!/bin/bash ##使用bash echo This is a list Bash Script echo S: list sizes echo L: List all file information echo C: list c Files echo -n "Please enther choice:" read choice ##等待用户输入 case $choice in s|S) ##如果输入的是s,不区分大小写 ls -s ;; l|L) ##如果输入的是l,不区分大小写 ls -l ;; c|C) ##如果输入的是c,不区分大小写 ls *.new ;; *) ##都不是的话 echo error esac [root@redhat ~]# chmod +x lss.sh [root@redhat ~]# ./lss.sh This is a list Bash Script S: list sizes L: List all file information C: list c Files Please enther choice:l total 69 -rw-r--r-- 1 root root 1251 Oct 24 15:01 anaconda-ks.cfg drwx------ 3 root root 1024 Oct 24 15:04 Desktop -rw-r--r-- 1 root root 545 Jan 19 15:22 genhtml.sh -rw-r--r-- 1 root root 47583 Oct 24 15:01 install.log -rw-r--r-- 1 root root 4702 Oct 24 15:01 install.log.syslog -rwxr-xr-x 1 root root 248 Jan 19 15:56 lss.sh -rw-r--r-- 1 root root 2737 Jan 6 12:45 main.cf.new -rw-r--r-- 1 root root 3125 Jan 6 12:45 master.cf.new -rwxr-xr-x 1 root root 263 Dec 5 17:39 userandgroupadd.sh |