Allan McRae wrote:
Cedric Staniewski wrote:
We could remove the quotes here, too.
Hmmm... can we. I know we can when there are spaces in a single variable, but for some reason I thought quotes were needed when joining multiple variables like that. I could be wrong...
[[ behaves quite different compared to [ in this aspect, but as far as I know, you do not need quotes to join variables as long as there are no spaces between the variables ;). There are several exceptions though, like cd for example, which require quotes even for single variables when they contain spaces. I think this has something to do with the type of the command. Builtins/external commands (usually) need quotes whereas everything else should work without. In my opinion, it is often not obvious whether they are required or not which is why I tended to use more quotes than actually were needed. I am fairly familiar with quoting by now and can use both "quoting styles", but I think it would probably be a good idea to decide for one. Using just as much quotes as required would be a little bit shorter, but using quotes `where possible` may be a little bit more foolproof. $ a=" a d" $ b=" e" $ c=$a:$b $ echo "$c" a d: e $ $ $ filename="a d e" $ suffix=".f" $ [ -e ${filename}${suffix} ] && echo 1 bash: [: too many arguments $ [[ -e ${filename}${suffix} ]] && echo 1 $ touch "${filename}${suffix}" $ [[ -e ${filename}${suffix} ]] && echo 1 1 $ [[ -e a d e.f ]] && echo 1 bash: syntax error in conditional expression bash: syntax error near `d' $ [[ -e "a d e.f" ]] && echo 1 1