4.Shell 判断用户的参数】的更多相关文章

1.Shell 判断用户的参数 系统在执行mkdir命令时会判断用户输入的信息,即判断用户指定的文件夹名称是否已经存在,如果存在则提示报错:反之则自动创建. Shell脚本中的条件测试语法可以判断表达式是否成立,若条件成立则返回数字0,否则便返回其他随机数值. 条件测试语法:的执行格式如图4-16所示.切记,条件表达式两边均应有一个空格 按照测试对象来划分,条件测试语句可以分为4种: 文件测试语句: 逻辑测试语句: 整数值比较语句: 字符串比较语句. 文件测试即使用指定条件来判断文件是否存在或权…
测试语句格式: [ 条件表达式 ] 常见的几种形式: [ -d /etc ]  判断/etc是不是一个目录类型, [ -e /etc/php.ini ] 判断/etc/php.ini 文件是否存在 [ -f /etc/php.ini ] 判断/etc/php.ini 是不是一般文件 [ -r /etc/php.ini ] 判断/etc/php.ini 当前用户是否有可读权限 [ -w /etc/php.ini ] 判断/etc/php.ini 当前用户是否有可写权限 [ -x /etc/php.…
1.Shell 传递参数 我们可以在执行 Shell 脚本时,向脚本传递参数,Linux系统中的Shell脚本语言已经内设了用于接收参数的变量,变量之间可以使用空格间隔. 例如$0对应的是当前Shell脚本程序的名称,$#对应的是总共有几个参数,$*对应的是所有位置的参数值,$?对应的是显示上一次命令的执行返回值, 而$1.$2.$3……则分别对应着第N个位置的参数值,如图4-15所示 尝试编写一个脚本程序示例: [root@linuxprobe ~]# vim example.sh #!/bi…
题目 写一个脚本 1. 传递一个参数给脚本,此参数为用户名: 2. 如果用户存在,则执行如下任务 * 如果用户的id号小于500,显示其为管理员或系统用户: * 否则,显示其为普通用户: 3. 如果用户不存在,则添加之: 解答 #!/bin/bash username=$1 if [ "$username" = "" ]; then echo "please input a username" exit 1 fi if id $username…
shell判断一个变量是否为空方法总结 https://www.jb51.net/article/154835.htm 1.判断变量 复制代码代码如下: read -p "input a word :" wordif  [ ! -n "$word" ] ;then    echo "you have not input a word!"else    echo "the word you input is $word"fi 2…
核心代码 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 if [ ! -x "$myPath"]; then mkdir "$myPath" fi #这里的-d 参数判断$myPath是否存在 if [ ! -d "$myPath"]; then…
1.  shell 的$! ,$?, $$,$@ $n        $1 the first parameter,$2 the second... $#        The number of command-line parameters. $0        The name of current program. $?        Last command or function's return value. $$        The program's PID. $!     …
转自:http://cqfish.blog.51cto.com/622299/187188 文章来源:http://hi.baidu.com/haigang/blog/item/e5f582262d639c118b82a167.html #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 if [ ! -x &…
http://blog.chinaunix.net/uid-7553302-id-183648.html 1  shell 的$! ,$?, $$,$@ $n        $1 the first parameter,$2 the second... $#        The number of command-line parameters. $0        The name of current program. $?        Last command or function'…