The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help with return code 1... mac4rfree Shell Programming and Scripting 6 12-11-2008 11:47 AM
FTP Return Code wilsonSurya UNIX for Dummies Questions & Answers 1 10-06-2008 08:27 AM
to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's manas6 UNIX for Dummies Questions & Answers 0 06-05-2008 07:44 AM
asking about return code naamas03 Shell Programming and Scripting 3 08-28-2007 05:53 AM
Return Code of tar in AIX dupeng AIX 3 02-23-2004 12:05 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-10-2009
learnbash learnbash is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 96
return code help

Hello folks,

I have a question that if i type ls command and type echo $? it always show "0", how i could do this change that when i type ls it will show me 1, actually i want to change the return code of commands from 0 to 1.

Thanks
Bash
  #2 (permalink)  
Old 02-10-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Code:
bash-2.05$ ls foo
foo: No such file or directory
bash-2.05$ echo $?
2
  #3 (permalink)  
Old 02-10-2009
learnbash learnbash is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 96
Quote:
Originally Posted by vgersh99 View Post
Code:
bash-2.05$ ls foo
foo: No such file or directory
bash-2.05$ echo $?
2

Hello,

thanks for your reply, but i want to replace only true output to "1", ls always return "0" how could i replace only ls command output to "1".

Thanks,
Bash
  #4 (permalink)  
Old 02-10-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Quote:
Originally Posted by learnbash View Post
Hello,

thanks for your reply, but i want to replace only true output to "1", ls always return "0" how could i replace only ls command output to "1".

Thanks,
Bash
no, 'ls' does not always return '0'.
here's what 'man ls' yields:
Code:
EXIT STATUS
     0     All information was written successfully.

     >0    An error occurred.
just curious, why would you want to return a non-zero value when 'ls' was successful?
  #5 (permalink)  
Old 02-10-2009
learnbash learnbash is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 96
Quote:
Originally Posted by vgersh99 View Post
no, 'ls' does not always return '0'.
here's what 'man ls' yields:
Code:
EXIT STATUS
     0     All information was written successfully.

     >0    An error occurred.
just curious, why would you want to return a non-zero value when 'ls' was successful?

Hello,

Thanks once again for quick reply, i understand what you are saying actually i want to make all commands return code to "1", ls is just an example.

Thanks.
Bash
  #6 (permalink)  
Old 02-10-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,884
Why? It's common practice in UNIX for programs to return 0 on successful exit (yes, I know it's different to C, where non-zero indicates success). If you want to change that, have fun updating and recompiling almost every util and shell for your OS.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0