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

The author's script (unknowingly) was relying on word splitting to convert string to cut-compatible format.

Shellcheck suggested: "Double quote to prevent globbing and word splitting."

Author implemented the suggestion, which (as advertised) prevented word splitting.

The script stopped working.

---

Related: every once in a while I talk to people who don't know how Unix argv vector works, and how come "system" takes space separated string which needs quoting, while "subprocess.run"/"execv" takes a list of strings which do not need quoting.

Anyone knows a good blog post with concise explanation of this concept that I can send them to? Because all I am finding is either manpage-level document which assumes reader already knows the concept, or huge books which mention many unrelated things as well.



How about this...

All programs take a list of arguments when they are executed.

Shell code, while it can be as simple as a program and list of arguments, is actually a small programming language.

In shell code

a b | tee a. log

Pipe is not an argument, it's code that the shell interprets.

system() takes shell code.


shellcheck's advice on double quoting has been plainly wrong a few times for me. I ignore shell check and use

bash - n




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

Search: