LINK="#3366FF" VLINK="#A000A0">



(?) The Answer Gang (!)


By Jim Dennis, Ben Okopnik, Dan Wilder, Breen, Chris, and the Gang, the Editors of Linux Gazette... and You!
Send questions (or interesting answers) to tag@lists.linuxgazette.net

There is no guarantee that your questions here will ever be answered. Readers at confidential sites must provide permission to publish. However, you can be published anonymously - just let us know!


(?) Bash

From Chris Twinn

Answered By Ben Okopnik

(?) I am trying to write a little bash script to update the crontab on RH7. Problem is that when I put

linetext = $1" * * * * " root bash /etc/cron.hourly/myscript or

(!) [Ben] Don't do that; you can't have any spaces around the '=' sign in variable assignment.

(?) linetext=$1" * * * * " root bash /etc/cron.hourly/myscript

I get back "2 configure ipchaser 2 configure ipchaser" which is an ls of that current directory fronted by the number 2 in my variable at each point of the star's.

(!) [Ben] Sure; it's doing exactly what you've asked it to do. Text in the weak (double) quotes is interpreted/interpolated by the shell; "*" does indeed mean "all files in the current directory". However, strong (single) quotes treat the enclosed text as a literal string; so does quoting it on assignment and output.
linetext=$1' * * * * root bash /etc/cron.hourly/myscript'
linetext="$1 * * * * root bash /etc/cron.hourly/myscript"
Either one of the above would result in "$linetext" containing
2 * * * * root bash /etc/cron.hourly/myscript
(this assumes that "$1" contains '2'.) Note that you have to echo it as
echo "$linetext"
not
echo $linetext
Otherwise, "bash" will still interpret those '*'s.

... he cheerfully reported back, his problem is solved ...

(?) Wicked.

(!) [Ben] On this side of the pond, the expression is "Duuuuude." :)

(?) Many Many Thanks.

(!) [Ben] Good to know you found it useful, Chris.


This page edited and maintained by the Editors of Linux Gazette Copyright © 2001
Published in issue 70 of Linux Gazette September 2001
HTML script maintained by Heather Stern of Starshine Technical Services, http://www.starshine.org/


[ Table Of Contents ][ Answer Guy Current Index ] greetings   1   2   3   4   5   6   7   8   9   10   11 [ Index of Past Answers ]