RHEL 6 Linux中的shell变量总结
查看/shellscripts/hello.sh是否可执行,可执行则输入yes,否则就赋予它可执行权限 [root@localhost shellscripts]# [ -x /shellscripts/hello.sh ] && echo yes || chmod +x /shellscripts/hello.sh [root@localhost shellscripts]# ls hello.sh ipadd.sh logmess_clean.sh [root@localhost shellscripts]# hello.sh hello world! “”和‘’与 ` ` 在shell变量中的区别 “ ” 允许通过$符引用其他变量 ‘’禁止引用其他变量符,视为普通字符 `` 将命令执行的结果输出给变量 [root@localhost ~]# echo "$PWD is lujing" /root is lujing [root@localhost ~]# echo '$PWD is lujing' $PWD is lujing [root@localhost ~]# echo $a 1000 [root@localhost ~]# echo $aaaaaaaa //系统把$aaaaa视为一个变量 [root@localhost ~]# echo ${a}aaaaaa //把变量用{}括起来,系统才会去输出变量 1000aaaaaa #echo `ls` 反引号中的命令时可以单独执行的,然后再由echo输出 扩展:” “反斜杠,作用屏蔽字符的特殊意义 test命令 用途:测试表达式是否成立,成立返回值为0,否返回值为其他值。 格式:test 条件表达式 [条件表达式] ≡ 常见的测试类型 测试文件的状态 字符的串比较 整数值比较 逻辑测试 测试文件的状态 格式:[操作符 文件或目录] 常见的测试操作符 -d :测试是否为目录【directory】 [root@localhost /]# [ -d /var/spool/ ] [root@localhost /]# echo $? 0 -e:测测试目录或文件是否存在【exist】 [root@localhost /]# [ -e /etc/passwd ] [root@localhost /]# echo $? 0 -f:测试是否为文件【file】 [root@localhost Packages]# [ -f /etc/passwd ] [root@localhost Packages]# echo $? 0 [root@localhost Packages]# -r:测试当前的用户是否有读取的权限【read】 [root@localhost /]# [ -r /etc/shadow ] [root@localhost /]# echo $? 0 [root@localhost /]# -w:测试当前的用户是否有写的权限【write】 [root@localhost /]# [ -w /etc/shadow ] [root@localhost /]# echo $? 0 [root@localhost /]# -x:测试当前的用户是否可执行和该文件【excute】 [root@localhost /]# [ -x /etc/shadow ] [root@localhost /]# echo $? 1 [root@localhost /]# ll /etc/shadow ----------. 1 root root 1086 2月 26 22:38 /etc/shadow -L:测试是否为符号链接文件【link】 [root@localhost /]# ll /etc/shadow ----------. 1 root root 1086 2月 26 22:38 /etc/shadow [root@localhost /]# [ -L /etc/shadow ] [root@localhost /]# echo $? 1 (编辑:常州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |