Go Back    

UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers


UNIX for Dummies Questions & Answers

Thread Tools Search this Thread Display Modes
Old 09-24-2008
bn_unx bn_unx is offline
Registered User
Join Date: Sep 2008
Last Activity: 3 February 2009, 1:24 PM EST
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts

if [ `echo ${cld}foo|grep $dow` ]; then
echo Its Cold for $sid at $c_dst
$jobroot/scripts/abc.sh $sid COLD $c_dst
elif [ `echo ${hot}foo|grep $dow` ]; then
echo Its Hot for $sid at $h_dst
$jobroot/scripts/abc.sh $sid HOT $h_dst
echo No backup for $sid today

wat does foo do ??

Last edited by bn_unx; 09-24-2008 at 03:46 PM.. Reason: ....
Sponsored Links
Old 09-25-2008
Smiling Dragon's Unix or Linux Image
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
Join Date: Nov 2007
Last Activity: 27 July 2017, 4:23 PM EDT
Location: New Zealand
Posts: 1,060
Thanks: 25
Thanked 29 Times in 28 Posts
It's a lazy coding hack used to prevent a syntax error in the event that $cid or $hot are not defined. The 'foo' part of the string doesn't prevent the match as grep ignores it. That said, it could actually cause it to break if $dow just happens to be "foo" (or some substring of it).
A tidier solution is to instead use "$cid" or to first evaluate "$cid" and check it's defined.
Sponsored Links
Old 09-25-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 11 Times in 9 Posts
And tidier still to avoid the rat's nest of test backticks echo.

case $dow in
    echo Its Cold for $sid at $c_dst
    $jobroot/scripts/abc.sh $sid COLD $c_dst;;
    echo Its Hot for $sid at $h_dst
    $jobroot/scripts/abc.sh $sid HOT $h_dst;;
    echo No backup for $sid today;;

This assumes some things about how $dow and $cld and $hot are set up; you might need to tweak this if they are not simply one-to-one, but you get the idea. This is IMHO much more readable, as well as more efficient.

If $dow is the numeric day of the week and the values of $cld and $hot are something like 7 (signifying Sunday) and 135 (Mon Wed Fri), then perhaps

case $cld:$hot in
  *$dow*:*)  echo it's cold;;
  *:*$dow*)  echo it's hot;;
  *) echo it's not;;

Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

All times are GMT -4. The time now is 09:07 AM.