What's the "right" way to do the following as a boolean expression?
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
...
The other solutions have a couple of common mistakes: http://www.pixelbeat.org/programming/shell_script_mistakes.html
for i in $(ls ...)
is redundant/problematic
just do: for i in $1/resources*; do ...
[ $i != file1 -a $1 != file2 ]
This actually has 2 problems.
a. The $i
is not quoted, hence names with spaces will cause issues
b. -a
is inefficient if stat
ing files as it doesn't short circuit (I know the above is not stat
ing files).
So instead try:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With