FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.

FutureQuest, Inc.
Go Back   FutureQuest Community > General Site Owner Support (All may read/respond) > General Coding/Development
User Name
Password  Lost PW

Reply
 
Thread Tools Search this Thread Display Modes
Old 02-12-2011, 04:12 AM   Postid: 179449
Trilby
Site Owner
 
Trilby's Avatar

Forum Notability:
63 pts: Helpful Contributor
[Post Feedback]
 
Join Date: Jan 2003
Posts: 31
Shell script "if" TRUE / FALSE

I'm hoping someone can clear up my confusion about true/false in shell scripts versus C programming.

For example:
Code:
if tar -cpvzf xxxxxx.tar.gz reports ztemp > xxxxxx.log
   then
      gzip -9 xxxxxx.log
   else echo bkup tar failed $?
fi
When the tar command is successful (returns 0), it seems to me the "if" should return "FALSE", but it doesn't -- it returns "TRUE". When the tar command fails (i.e., returns value > 0), the "if" returns "FALSE", but it seems to me that's "TRUE".

I'm confused...... (and thanks for any clarification)
Trilby is offline   Reply With Quote
Old 02-12-2011, 06:55 AM   Postid: 179450
hobbes
Have you hugged a tiger today?
 
hobbes's Avatar

Forum Notability:
1238 pts: A True Crowd-pleaser!
[Post Feedback]
 
Join Date: Mar 2000
Location: Third Sol Planet Posts: Far too many. Oh ok -
Posts: 2,721
Re: Shell script "if" TRUE / FALSE

When you execute a UNIX/Linux command, it returns a status of either 0 (success) or # (error code).
hobbes is offline   Reply With Quote
Old 02-12-2011, 10:56 AM   Postid: 179453
 Kevin
Systems Administrator
 
Kevin's Avatar
 
Join Date: Aug 2001
Location: Orlando, FL
Posts: 2,560
Re: Shell script "if" TRUE / FALSE

If you want to be even more confused that can all be done on one line using logical operators:

Code:
tar -cpvzf xxxxxx.tar.gz reports ztemp > xxxxxx.log && gzip -9 xxxxxx.log || echo bkup tar failed $?
If you want the script to output that error and then stop executing then just exec the echo.
__________________
Kevin
Kevin is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 visitors)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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


Running on vBulletin®
Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.
Hosted & Administrated by FutureQuest, Inc.
Images & content copyright © 1998-2014 FutureQuest, Inc.
FutureQuest, Inc.