Bash 在shell脚本中检查umask

Bash 在shell脚本中检查umask,bash,sh,umask,Bash,Sh,Umask,如何检查umask是否阻止设置组位?我的尝试: #!/bin/sh out=$(umask) echo "$out" if (($out & 070) != 0); then echo "$out" echo "Incorrect umask" > /dev/tty exit 1 fi 输出: ./test.sh: line 6: syntax error near unexpected token `!=' ./test.sh: line 6: `i

如何检查umask是否阻止设置组位?我的尝试:

#!/bin/sh

out=$(umask)
echo "$out"

if (($out & 070) != 0); then
    echo "$out"
    echo "Incorrect umask" > /dev/tty
    exit 1
fi
输出:

./test.sh: line 6: syntax error near unexpected token `!='
./test.sh: line 6: `if (($out & 070) != 0); then'

如果bash能让事情变得更简单的话,我可以切换到它。

您需要使用双括号来获得算术计算。看

或者您可以将umask视为字符串并使用:


bash有很多独特的语法:它根本不像C/perl。阅读(或至少参考)手册,并在此处阅读大量问题。继续提问。

你的问题因为“太宽泛”而接近票数。与其要求我们编写整个解决方案,不如尽最大努力自己编写,如果无法使其正常工作,请在此处发布您所写的内容,并请求帮助修复它。到目前为止,我的尝试是一场灾难。我已经加上了这个问题,谢谢。我想你需要
if[$umask&070-ne 0]
或者
if[$umask&070]
。用谷歌快速搜索并不难。
/test.sh:line 6:[:missing]。/test.sh:line 6:070:command not found
是我早些时候尝试时得到的结果,你在某处遗漏了一个空格。你需要复制我写的东西。我在寻找的答案。特别是最后一部分。谢谢我想实际链接到手册:
m=$(umask)
if (( ($m & 070) != 0 )); then 
    echo error
fi
if [[ $m == *0? ]]; then
    echo OK
else
    echo err
fi