for your eyes only
Knowledge Hurts – a blog of thoughts, things and stuff.

I have a nice s…

I have a nice script and want to read its return value in a “bash -c” statement. Here is my script:

exit 100 

and this is what happens when I execute it:

bash; echo $? 

Nice! It shows me the return value! But wait – what if I use bash -c to run these 2 commands in a subshell? 

bash -c "bash; echo $?" 

WTF? It shows me 0 as return value? That can’t be! Well – yes it can. And here is the way to do it right:

bash -c 'bash; echo $?' 

Using single quotes (‘) instead of double quotes (“), I get what I want. I execute a subshell, run a script inside it and can read the return value from the $? variable! IT’S MAGIC!!!


No Responses to “I have a nice s…”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: