5

この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
4

2 に答える 2

9

Add a space after [ and before ].

[ -d $1 ]
 ^     ^
于 2013-05-22T14:35:39.897 に答える
1

と の前後にスペースが必要[です]。詳細help [については、を参照してください。

于 2013-05-22T14:36:44.703 に答える