将以下内容作为布尔表达式的"正确"方法是什么?
for i in `ls $1/resources`; do if [ $i != "database.db" ] then if [ $i != "tiles" ] then if [ $i != "map.pdf" ] then if [ $i != "map.png" ] then svn export -q $1/resources/$i ../MyProject/Resources/$i ...
pixelbeat.. 11
其他解决方案有几个常见的错误:http: //www.pixelbeat.org/programming/shell_script_mistakes.html
for i in $(ls ...)
是多余的/有问题的只是做: for i in $1/resources*; do ...
[ $i != file1 -a $1 != file2 ]
这实际上有两个问题.
一个.在$i
没有加引号,因此用空格会导致一些问题名
湾 -a
如果stat
文件没有短路(我知道上面不是stat
文件),效率很低.
所以请尝试:
for i in $1/resources/*; do
if [ "$i" != "database.db" ] &&
[ "$i" != "tiles" ] &&
[ "$i" != "map.pdf" ] &&
[ "$i" != "map.png" ]; then
svn export -q "$i" "../MyProject/Resources/$(basename $i)"
fi
done
Mo... 7
更短:
for i in `ls $1/resources`; do if [ $i != databse.db -a $i != titles -a $i != map.pdf ]; then svn export -q $1/resources/$i ../MyProject/Resources/$i fi done;
的-a
在如果expression布尔AND壳式测试的等效.欲了解更多man test
其他解决方案有几个常见的错误:http: //www.pixelbeat.org/programming/shell_script_mistakes.html
for i in $(ls ...)
是多余的/有问题的只是做: for i in $1/resources*; do ...
[ $i != file1 -a $1 != file2 ]
这实际上有两个问题.
一个.在$i
没有加引号,因此用空格会导致一些问题名
湾 -a
如果stat
文件没有短路(我知道上面不是stat
文件),效率很低.
所以请尝试:
for i in $1/resources/*; do
if [ "$i" != "database.db" ] &&
[ "$i" != "tiles" ] &&
[ "$i" != "map.pdf" ] &&
[ "$i" != "map.png" ]; then
svn export -q "$i" "../MyProject/Resources/$(basename $i)"
fi
done
更短:
for i in `ls $1/resources`; do if [ $i != databse.db -a $i != titles -a $i != map.pdf ]; then svn export -q $1/resources/$i ../MyProject/Resources/$i fi done;
的-a
在如果expression布尔AND壳式测试的等效.欲了解更多man test