linux – bash,找不到命令

参见英文答案 > Why should there be a space after ‘[‘ and before ‘]’ in Bash?                                    4个
我在修复这个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
最佳答案
在[和之前]之后添加一个空格.

[ -d $1 ]
 ^     ^

相关文章

linux常用进程通信方式包括管道(pipe)、有名管道(FIFO)、...
Linux性能观测工具按类别可分为系统级别和进程级别,系统级别...
本文详细介绍了curl命令基础和高级用法,包括跳过https的证书...
本文包含作者工作中常用到的一些命令,用于诊断网络、磁盘占满...
linux的平均负载表示运行态和就绪态及不可中断状态(正在io)的...
CPU上下文频繁切换会导致系统性能下降,切换分为进程切换、线...