> Is there any way to nest backticks? What I mean is follows: > localhost% echo "You have `expr `frm | wc -l` - 1` messages."
in ksh or sh, you might try:
echo "You have `expr \`frm | wc -l\` - 1` messages."
If you _must_ use csh, then put this into a script:
#!/bin/sh echo "You have `expr \`frm | wc -l\` - 1` messages."
For ksh, there is a more readable syntax (to me, anyway)…
$ echo "You have $(expr $(frm | wc -l) -1) messages."
Dave
There's also the $() notation, found in POSIX-compliant shells:
$ echo You have $(expr $(frm | wc -l) - 1) messages.
Neater, simpler, and washes whiter.
Simon
> Are there any differences between $() and backticks, except from how easy > they are to nest?
Backticks are available in all shells, i.e., sh, ksh, bash, csh, …, while $(…) can be found in ksh, bash, and other POSIX shells.
You're always on the safe side when you use backticks, however, this can be a pain in the neck when nesting.
Jens M. Felderhoff
The backtick form does an extra level of quote processing before
executing the contained command, and the $() form doesn't, so you can
test a command outside of $() and not have to worry about adding
quotes. Certain kinds of commands work poorly if at all inside
backticks; the examples of this I've seen all involve here-documents.
In addition, though it's not as big a deal, $(<filename) does the same
thing as `cat filename`
without creating another process.
Eric Amick
documented on: 1999.11.04 Thu 16:52:36