Linux Today: Linux News On Internet Time.

More on LinuxToday

Speaking UNIX: Go Fish! The Friendly Interactive Shell

Dec 04, 2008, 15:33 (0 Talkback[s])
(Other stories by Martin Streicher)

[ Thanks to An Anonymous Reader for this link. ]

"English is a perplexing language. For example, consider the words moon and good. To the uninitiated, the words should rhyme, but the former is pronounced /mun/ (according to the International Pronunciation Alphabet), while the latter is spoken /good/. Seemingly, the only rule in English is exception.

"UNIX shells are equally perplexing. For instance, in the Bourne shell (and most common UNIX shells), the phrases '$var', "$var", and `$var` look alike but yield substantially different results. (Each CLI in the shell examples presented in this article are prefaced with the name of the active shell and the command number.)

"In the sequence above, the variable var is set to the two-letter string ls. In the initial echo command, the apostrophes prevent interpretation of the variable, instead yielding a verbatim copy of the quoted text, the four-letter string $var. Next, in command 4, the double quotation marks do interpret the variable, so the result is the string ls. Finally, the back quotes both interpret the variable and run the intermediate result as a subshell. Thus, `$var` yields the intermediate string ls, which runs as a shell command to produce the contents of the local directory."

Complete Story

Related Stories: