Bash脚本错误0 = 1:找不到命令 [英] Bash-Script Error 0=1: command not found

查看:46
本文介绍了Bash脚本错误0 = 1:找不到命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是用bash开始一些脚本.现在我遇到了以下错误:

I'm just starting with some scripts with the bash. Now I got the following errors:

  • 0 = 1:在第9行上找不到命令.
  • 主页*错误:在第17行上找不到命令

我想用我的脚本检查主目录和以后的其他一些目录是否存在并具有正确的权限.

I want to check with my script if the home-directory and later some other directories exist and have the right permission.

我已经在Google和Stack Overflow上进行了搜索,但没有找到答案.首先,变量和它们的赋值之间有太多空格.我认为我已解决此错误,但仍然有其他错误没有找到答案.

I have already searched with Google and on Stack Overflow but I didn't find an answer. First I had too many spaces between the variables and their assigned value. This error I think I fixed but still there are other errors for which I didn't find an answer.

感谢您的帮助,在这里您可以从脚本中看到我的代码:

Thanks for you help and here you can see my code from the script:

#!/bin/bash
users=(Hans Peter Alfred Georg Stefan Albert Christine)
for user in ${users[@]};
do

   nutzerVerzeichnis="0"
   if [ -d "/home/${user}" ]
   then
           ${nutzerVerzeichnis}="1"
           echo $home_dir
   fi

   if [ "${nutzerVerzeichnis}" -eq "1" ]
   then
           "Home ${user} ok">>/root/skript/permission.log
   else
           "Home ${user} Error">>/root/skript/permission.log
   fi
done
exit 0

推荐答案

在这一行:

${nutzerVerzeichnis}="1"

您告诉它要评估其nutzerVerzeichnis的值为0.因此,它与书写相同.

You are telling it to evaluate to the value of nutzerVerzeichnis which is 0. Therefore it is the same as writing.

0=1

如果您尝试为它分配一个值,则将$ {}保留为此

if your trying to assign it a value instead then leave off the ${} to this

nutzerVerzeichnis="1"

您的代码中还有其他一些错误.这是更正的代码.

There are also a few other mistakes in your code. Here is the corrected code.

#!/bin/bash
users=(Hans Peter Alfred Georg Stefan Albert Christine)
for user in "${users[@]}";
do
    nutzerVerzeichnis="0"
    if [ -d "/home/${user}" ]
    then
            nutzerVerzeichnis="1"
            echo "$home_dir"
    fi

    if [ "${nutzerVerzeichnis}" -eq "1" ]
    then
            echo "Home ${user} ok" >> /root/skript/permission.log
    else
            echo "Home ${user} Error" >> /root/skript/permission.log
    fi
done
exit 0

这篇关于Bash脚本错误0 = 1:找不到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆