Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



> 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...., and now I've added that, thanks :)


The latter can be avoided with “shopt -s failglob”.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: