- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- return code
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2001 12:52 PM
тАО11-13-2001 12:52 PM
which executes the command and prints it.
Is there a way to capture proper return code from the command.
It awlays returns RC=0.
LST=cmd.lst; >$LST
RC=0
runcmd()
{
echo "`date '+%H:%M:%S '`\c" |tee -a $LST
echo "\n$CMD \n$(eval $CMD) RC=$?" |tee -a $LST
};
CMD="grep -il admm /etc/passwd*"
runcmd
echo $RC
if [ "$RC" != 0 ]; then
echo "Error - $RC " |tee -a $LST
fi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2001 12:57 PM
тАО11-13-2001 12:57 PM
Re: return code
echo $?
or
if [ $? !-eq 0 ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2001 01:01 PM
тАО11-13-2001 01:01 PM
Re: return code
# ./tmp/dah
16:00:34
grep -il admm /etc/passwd*
RC=1
0
#
???
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2001 01:04 PM
тАО11-13-2001 01:04 PM
Re: return code
echo "\n$CMD \n$(eval $CMD) RC=$?" |tee -a $LST
is not setting RC to $?, it's just echo'ing "RC="$?
Is that what you want it to do?
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2001 01:07 PM
тАО11-13-2001 01:07 PM
Re: return code
I was not clear perhaps
I want to set RC so I can examine it later
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2001 01:27 PM
тАО11-13-2001 01:27 PM
Solutionecho "\n$CMD " |tee -a $LST
whatgoes=$(eval $CMD)
RC=$?
echo $whatgoes RC=$RC |tee -a $LST
If you do it after the command is executed and you "tee" the output, then $? will be equal to the return code of the "tee", which is 99.999% always 0.
live free or die
harry