suicidaleggroll |
12-17-2014 04:40 PM |
Put quotes around your variable in the for loop, same as you would if there's a space or any other "bad" character.
Code:
$ touch a b
for a in *\(c\)*; do ls $a; done
a b
$ for a in *\(c\)*; do ls "$a"; done
ls: cannot access *(c)*: No such file or directory
same as this
Code:
$ touch "a b"
$ ls *\ *
a b
$ for a in *\ *; do ls $a; done
ls: cannot access a: No such file or directory
ls: cannot access b: No such file or directory
$ for a in *\ *; do ls "$a"; done
a b
If there's ever a chance you're going to have a character that requires delimiting (-, (, space, etc.) stored inside a variable, then you need to stick quotes around it when you use it.
|