Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to use a return code in an if statement? Post 302452307 by zaxxon on Friday 10th of September 2010 12:52:18 AM
Old 09-10-2010
I would go for something like this:
Code:
pkginfo TestPackage > /dev/null 2>&1         # we do not want any output
if [ $? = 0 ]; then
   echo yeah
else
   echo doh
fi

And btw, this looks strange:
Code:
"$`{pkginfo TestPackage}`"

If you want to execute a command, don't write it like a variable, ie. leave out the $ and the {}. This is what works:
Code:
VAR=$(somecommand)
# or
VAR=`somecommand`

This User Gave Thanks to zaxxon For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Return code from PL/SQL Code

Hi Guys, I was just wondering if anybody can help me with this problem. OK, how we can get a value back from PL/SQL Script (not stored procedure/function) See the below example: (for example aaa.sh) #!/bin/ksh VALUE=`sqlplus -s user/password@test_id <<EOF @xxx.sq EOF` echo $VALUE ... (7 Replies)
Discussion started by: Shaz
7 Replies

2. Shell Programming and Scripting

asking about return code

hi all my system is linux red hat i have a script that runs some object . the object return some code to the system i see the code by writing echo $? i want to ask in the script if $? equals 14 how shell is do that in the script thanks (3 Replies)
Discussion started by: naamas03
3 Replies

3. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

4. Shell Programming and Scripting

checking the return code

hi i have a file, i am reading line by line and checking a line contains a string , `grep "Change state" $LINE` if then echo "The line contains---" else echo "The line does not contains---" i need to check the return code , but i am getting an error ... (4 Replies)
Discussion started by: Satyak
4 Replies

5. Shell Programming and Scripting

Need help with return code 1...

Hi Guys,, I am having a unix script which is running the DB2 Insert command. For the insert command, there were no records to be updated. SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. SQLSTATE=02000 + + echo 1 STAGE_RC=1 + ] ... (6 Replies)
Discussion started by: mac4rfree
6 Replies

6. Shell Programming and Scripting

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 (5 Replies)
Discussion started by: learnbash
5 Replies

7. Shell Programming and Scripting

::select statement return value with correct field size::

Hi Everyone, I am facing a problem regarding the select from sybase, the return with the incorrect size. For example, field is NAME(20). After i selected from sybase, the result is nicky. after i assign it to another declaration variable, it will be in actual name "nicky" , what i need... (10 Replies)
Discussion started by: ryanW
10 Replies

8. Shell Programming and Scripting

How could I use the value of return code

Hello, I am woring on a script where I am getting strange situation.This script actually fetch the source code and tar that code and send to NAS location.This code resides in MKS tool...and we are fetching the source code on checkpoint label basis and script is working fine.First it synch the... (0 Replies)
Discussion started by: anuragpgtgerman
0 Replies

9. Shell Programming and Scripting

If echo statement return false

I have this code that sometimes return a false value and the code inside the if statement gets executed and error out. Any idea why? thanks. So I set a debug and see what the value for $ScriptElapsedTime Here is the value I got ScriptElapsedTime='03:20'. Base on this value the if... (10 Replies)
Discussion started by: nugent
10 Replies

10. Shell Programming and Scripting

How to retrieve "case "statement return value ?

How do we retrieve case statement return value at point indicated in the attached snippet case "$FUN" in 1\ *) do_change_pass ;; 2\ *) do_network_menu ;; 3\ *) do_boot_menu ;; 4\ *) do_internationalisation_menu ;; 5\ *) do_ssh... (6 Replies)
Discussion started by: annacreek
6 Replies
PPIx::EditorTools::ReturnObject(3pm)			User Contributed Perl Documentation		      PPIx::EditorTools::ReturnObject(3pm)

NAME
PPIx::EditorTools::ReturnObject - Simple object to return values from PPIx::EditorTools SYNOPSIS
my $brace = PPIx::EditorTools::FindUnmatchedBrace->new->find( code => "package TestPackage; sub x { 1; " ); my $location = $brace->element->location; my $ppi = $brace->element->ppi; DESCRIPTION
Retuning a simple "PPI::Element" from many of the "PPIx::EditorTools" methods often results in the loss of the overall context for that element. "PPIx::EditorTools::ReturnObject" provides an object that can be passed around which retains the overall context. For example, in "PPIx::EditorTools::FindUnmatchedBrace" if the unmatched brace were returned by its "PPI::Structure::Block" the containing "PPI::Document" is likely to go out of scope, thus the "location" method no longer returns a valid location (rather it returns undef). Using the "ReturnObject" preserves the "PPI::Document" and the containing context. METHODS
new() Constructor which should be used by "PPIx::EditorTools". Accepts the following named parameters: ppi A "PPI::Document" representing the (possibly modified) code. code A string representing the (possibly modified) code. element A "PPI::Element" or a subclass thereof representing the interesting element. ppi Accessor to retrieve the "PPI::Document". May create the "PPI::Document" from the $code string (lazily) if needed. code Accessor to retrieve the string representation of the code. May be retrieved from the "PPI::Document" via the serialize method (lazily) if needed. SEE ALSO
"PPIx::EditorTools", App::EditorTools, Padre, and PPI. perl v5.14.2 2012-03-11 PPIx::EditorTools::ReturnObject(3pm)
All times are GMT -4. The time now is 07:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy