【问题标题】:bash, command not found [duplicate]bash,找不到命令[重复]
【发布时间】:2013-05-17 16:06:36
【问题描述】:

我在修复这个 bash 脚本中的错误时遇到了麻烦,我真的不知道我做错了什么,感谢任何帮助

[centoslive@livecd ~]$ sh ListFich.sh test
Synthese, Question 2
ListFich.sh: line 9: [-d: command not found
Il n'y a aucun repertoire qui se nomme test
ListFich.sh: line 15: [-f: command not found
Il n'y a aucun fichier qui se nomme test
[centoslive@livecd ~]$ 
#!bin/bash

echo "Synthese, Question 2"

if test $# -eq 0; then
    echo "Argument Manquants"
    exit 1 
else 
    if [-d $1];then
        ls -d $1
        exit 1
    else 
        echo "Il n'y a aucun repertoire qui se nomme $1"
    fi
    if [-f $1]; then
        if [ -s $1]; then
            ls -l $1
            exit 1
        else 
            ls -l $1
            echo "Le fichier $1 est vide"
            exit 1
        fi
    else 
        echo "Il n'y a aucun fichier qui se nomme $1"   
    fi
fi

【问题讨论】:

  • 您似乎在成功退出 1;按照约定表示失败。

标签: linux bash shell


【解决方案1】:

之后[之前]添加一个空格。

[ -d $1 ]
 ^     ^

【讨论】:

  • @JoeE:当您使用它时,请考虑使用[[]] -- bash 更强大的内置函数,它们提供了额外的运算符(=~、)并且不需要引用你的字符串操作数。
  • this link 介绍了 [[[ 之间的主要区别。
  • 愿意解释原因并提供一些参考链接吗?这将使这个答案更加有用!
  • @Kissaki 见上一条评论。
  • @tarrssailah 我看到了那个评论。这主要/目标是一个问答网站,而不是一个问答网站。答案应该尽可能完整,所以不是每个寻找答案的人都需要阅读所有的 cmets。
【解决方案2】:

[] 前后需要空格。详情请见help [

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-23
    • 2012-06-06
    • 2013-03-22
    • 2015-01-22
    • 2022-11-24
    • 2020-04-08
    • 2016-01-02
    • 2018-12-10
    相关资源
    最近更新 更多