shell脚本空格规范

shell脚本空格规范


练习,写一个脚本:

传递一个用户名参数给脚本,判断此用户用户名跟其基本组的组名是否一致,并将结果显示出来


#!/bin/bash

#

if ! id $1 &>/dev/null;then

echo "No such user !"

exit 10

fi


if [`id -n -u $1` == `id -n -g $1` ];then


#if [ $1 == `id -n -g $1` ];then

echo "User group same!"

else

echo "User group difference!"

fi


注意 开头为 “if”的行,[ 与 `之间要有空格,如果没有,运行时会有以下提示

[root@localhost ~]# ./ugsame.sh test002

./ugsame.sh:行3: [test002: 未找到命令

User group diffrence!


加了空格后,如

if[ `id -n -u $1` == `id -n -g $1` ];then

就可以正常运行,运行结果如下


[root@localhost ~]# ./ugsame.sh test002

User group same!

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...