1

私のOS:Fedoraリリース13(ゴダード)

「test」の下には5つのディレクトリがあります

[root@localhost lab]# ls test
dir1  dir2  dir3  dir4  dir5

スクリプト1

#!/bin/bash
#below line for listing all directories under '/home/arun/lab/test'
ls -Al --time-style=long-iso /home/arun/lab/test | grep '^d' | awk '{print $8}' | while read line
do
#Need to skip few directoirs
if [ "$line" == "dir1" -o "$line" == "dir2" ]; then
continue
fi
#will take some actions here..as of now just echo only
echo $line
done

Script2 [変更のみ == を != に変更]

#!/bin/bash
#below line for listing all directories under '/home/arun/lab/test'
ls -Al --time-style=long-iso /home/arun/lab/test | grep '^d' | awk '{print $8}' | while read line
do
#Need to skip few directoirs
if [ "$line" != "dir1" -o "$line" != "dir2" ]; then
continue
fi
#will take some actions here..as of now just echo only
echo $line
done

期待される o/p を与えるスクリプト 1

[root@localhost lab]# ./test.sh 
dir3
dir4
dir5

問題は次のとおり です。スクリプト 2 については、o/p 以下を期待しています。しかし、実行中にo / p [空白]はありません..これで私を助けてください。

[root@localhost lab]# ./test.sh 
dir1
dir2
4

1 に答える 1

3

2 番目のスクリプトでは、 ("or" -a) ではなく ("and")が必要です。-o論理を考えてみてください: すべての可能な文字列は 2 つのうちの少なくとも 1 つと等しくありませんが、どちらとも等しくない場合、つまり「dir1」等しくなく、等しくない場合はスキップしたいと考えています。 「dir2」に。

于 2012-12-20T11:43:31.320 に答える