4 ms·
sysadmin...sense...tingling... Get in the habit of putting $file (and, in this case, ${file%.jpg}_s.jpg) in double quotes. Your one-liner (and theirs) will bl
by rwg 13y ago
sysadmin...sense...tingling...
Get in the habit of putting $file (and, in this case, ${file%.jpg}_s.jpg) in double quotes. Your one-liner (and theirs) will blow up spectacularly if there's whitespace in a filename:
bash-3.2$ for i in 'lots of spaces'.jpg '1 2'.jpg; do printf 'arg = %s\n' ${i%.jpg}_s.jpg; done
arg = lots
arg = of
arg = spaces_s.jpg
arg = 1
arg = 2_s.jpg
bash-3.2$ for i in 'lots of spaces'.jpg '1 2'.jpg; do printf 'arg = %s\n' "${i%.jpg}_s.jpg"; done
arg = lots of spaces_s.jpg
arg = 1 2_s.jpg
EDIT: It's also worth noting that, by default, zsh doesn't split on whitespace in parameter expansion like sh, bash, etc. do. ("man zshexpn" and search for "SH_WORD_SPLIT")