1

我的操作系统:Fedora 13 版(Goddard)

'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

脚本 1 给出预期的 o/p

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

问题是: 对于脚本 2,我期望低于 o/p。但是运行时没有o / p [空白]..请帮助我。

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

1 回答 1

3

对于第二个脚本,您需要-a("and") 而不是-o("or")。思考逻辑:每个可能的字符串都不等于两者中的至少一个,但是当它不等于其中任何一个时,您想跳过,也就是说,当它不等于“dir1”并且也不等于时到“dir2”。

于 2012-12-20T11:43:31.320 回答