foo | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    

UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!


UNIX for Dummies Questions & Answers

Closed Thread    
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/ $sid COLD $c_dst
elif [ `echo ${hot}foo|grep $dow` ]; then
echo Its Hot for $sid at $h_dst
$jobroot/scripts/ $sid HOT $h_dst
echo No backup for $sid today

wat does foo do ??

Last edited by bn_unx; 09-24-2008 at 04:46 PM.. Reason: ....
Sponsored Links
Old 09-25-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
Join Date: Nov 2007
Last Activity: 7 January 2015, 9:08 PM EST
Location: New Zealand
Posts: 1,048
Thanks: 21
Thanked 26 Times in 25 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 10 Times in 8 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/ $sid COLD $c_dst;;
    echo Its Hot for $sid at $h_dst
    $jobroot/scripts/ $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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

All times are GMT -4. The time now is 06:10 AM.