Bash脚本错误0 = 1:找不到命令

编程入门 行业动态 更新时间:2024-10-24 16:24:26
本文介绍了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:找不到命令

本文发布于:2023-10-13 10:30:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1487704.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   脚本   命令   错误   Bash

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!