Re: Bash Quirkiness

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 26 Jul 2004, David Cary Hart wrote:

Bash is astonishingly fussy about spacing and punctuation.

Here's a (admittedly very inelegant) snippet of code to automatically
generate exploit abuse complaints from a cron job.

while read evil freq ; do
	if [ "$freq" -gt 250 ] ; then
		a=`host $evil`
		c=`expr "$a" : '.*\(\..*\.net\)'`
		evilisp=${c/\./abuse\@}
			if [ $evilisp > "0" ] ; then
. . . . .

Note the use of both ' and ` in the line with the "expr." I find that
they are not interchangeable. Assigning a variable to an 'expr' will not
work without the "`". In fact, I cut and pasted it from some web docs.
I'm not even really sure what character it is.

it's short for "command substitution", which runs the command contained with the ` quotes and produces what's printed to standard output. *very* different from the regular single quotes -- you *bet* they're not interchangeable.


to avoid confusion, you can also identify command substitution with the syntax $(... command ...), which i personally prefer, since it's much clearer. that is, you'd be better off writing:

     c=$(expr ... ')

at least, in my opinion.

rday



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux