4 ms·
Assuming the first example is in Bash: - You're not quoting your variables properly to prevent splitting and globbing. - In case there are no jpg files in the
by frankjr 2y ago
Assuming the first example is in Bash:
- You're not quoting your variables properly to prevent splitting and globbing.
- In case there are no jpg files in the working directory, Bash will put the pattern itself (*.jpg) into the $x variable. You need to explicitly check that the file in the variable actually exists before working on it.
Modern shells do not have these footguns.
- teddyh 2y agoThe latter can be avoided with “shopt -s failglob”.
- xiaq 2y ago> In case there are no jpg files in the working directory, Bash will put the pattern itself (*.jpg) into the $x variable. You need to explicitly check that the file in the variable actually exists before working on it. Indeed that's one thing Elvish has better defaults that I forgot to mention in https://elv.sh/learn/scripting-case-studies.html#jpg-to-png.elv https://elv.sh/learn/scripting-case-studies.html#jpg-to-png...., and now I've added that, thanks :)