The importance of an ordinary space in a Unix shell command line

#104 · ✸ 61 · 💬 6 · 12 days ago · utcc.utoronto.ca · zdw · 📷
In the sidebar to yesterday's entry I made a Unix command line mistake by unthinkingly leaving out an ordinary, innocent looking space. This innocent looking mistake and its consequences are an illustration of something in Unix shell command lines, although I'm not sure of just what, so I'm going to write it up. Read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ]. The 'read' builtin follows the general standard behavior of Unix commands where '-d delim' and other options that take an argument can be shortened to omit the space, so '-ddelim'. I've used '' to create an empty argument and then I've done the standard thing of removing the space between -d and its argument. So clearly I've given '-d' an empty argument, right? Nope. The fundamental problem is that Unix command line arguments can't include NUL characters, because the Unix command line API passes the arguments as an array of NUL-terminate strings. No matter how you invoke a program, the first NUL character in an argument is the end of that argument from the program's perspective.
The importance of an ordinary space in a Unix shell command line



Send Feedback | WebAssembly Version (beta)