152 csh, pipes, and find Date: Mon, 7 May 90 18:00:27 -0700 From: Andy Beals bandy@lll-crg.llnl.gov Subject: Re: today’s gripe: fg %3 To: UNIX-HATERS Not only can you say %emacs or even %e to restart a job [if it’s a unique completion], one can also say %?foo if the substring “foo” appeared in the command line. Of course, !ema and !?foo also work for history substitution. However, the pinheads at UCB didn’t make !?foo recognize subse- quent editing commands so the brain-damaged c-shell won’t recog- nize things like !?foo:s/foo/bar&/:p making typing a pain. Was it really so hard to scan forward for that one editing character? All of this gets a little confusing, even for Unix “experts.” Take the case of Milt Epstein, who wanted a way of writing a shell script to determine the exact command line being typed, without any preprocessing by the shell. He found out that this wasn’t easy because the shell does so much on the program’s “behalf.” To avoid shell processing required an amazingly arcane incantation that not even most experts can understand. This is typi- cal of Unix, making apparently simple things incredibly difficult to do, simply because they weren’t thought of when Unix was first built: Date: 19 Aug 91 15:26:00 GMT From: Dan_Jacobson@att.com Subject: ${1+“$@”} in /bin/sh family of shells shell scripts Newsgroups: comp.emacs,gnu.emacs.help,comp.unix.shell On Sun, 18 Aug 91 18:21:58 -0500, Milt Epstein epstein@suna0.cs.uiuc.edu said: Milt what does the “${1+“$@”}” mean? I’m sure it’s to Milt read in the rest of the command line arguments, but Milt I’m not sure exactly what it means. It’s the way to exactly reproduce the command line arguments in the /bin/sh family of shells shell script.
The Shell Game 153 It says, “If there is at least one argument ( ${1+ ), then substitute in all the arguments ( “$@” ) preserving all the spaces, etc. within each argument. If we used only “$@” then that would substitute to “” (a null argu- ment) if there were no invocation arguments, but we want no argu- ments reproduced in that case, not “”. Why not “$*” etc.? From a sh(1) man page: Inside a pair of double quote marks (“”), parameter and command substitution occurs and the shell quotes the results to avoid blank interpretation and file name generation. If $* is within a pair of double quotes, the positional parameters are substituted and quoted, separated by quoted spaces (“$1 $2 …”) however, if $@ is within a pair of double quotes, the positional parameters are substituted and quoted, separated by unquoted spaces (“$1” “$2” …). I think ${1+“$@”} is portable all the way back to “Version 7 Unix.” Wow! All the way back to Version 7. The Shell Command “chdir” Doesn’t Bugs and apparent quirky behavior are the result of Unix’s long evolution by numerous authors, all trying to take the operating system in a different direction, none of them stopping to consider their effects upon one another. Date: Mon, 7 May 90 22:58:58 EDT From: Alan Bawden alan@ai.mit.edu Subject: cd . . : I am not making this up To: UNIX-HATERS What could be more straightforward than the “cd” command? Let's consider a simple case: “cd ftp.” If my current directory, /home/ar/alan, has a subdirectory named “ftp,” then that becomes my new current directory. So now I’m in /home/ar/alan/ftp. Easy. Now, you all know about “.” and “. .”? Every directory always has two entries in it: one named “.” that refers to the directory itself, and one named “. .” that refers to the parent of the directory. So in our example, I can return to /home/ar/alan by typing “cd . .”.
Previous Page Next Page