bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about exit command


From: Davide Brini
Subject: Re: question about exit command
Date: Wed, 19 Jan 2011 10:49:47 +0000
User-agent: KMail/1.13.5 (Linux/2.6.36-gentoo-r5; KDE/4.4.5; x86_64; ; )

On Wednesday 19 Jan 2011 10:42:21 ali hagigat wrote:

> I have two script files and I execute them as follows:
> -------------------------------------
> #script1
> echo ppp
> exit 0
> echo qqq
> /root> ./script1
> ppp
> -------------------------------------
> #script2
> if (exit 0) then
>     echo ppp
> fi
> /root> ./script2
> ppp
> -------------------------------------
> In script1, when exit executes, it returns and immediately
> shell(/bin/bash) returns too. Why in the second script shell completes
> if command and does not return immediately? In script 2, what will be
> the return value of shell? The option of exit or the return value of
> echo?

In your second script, the "exit 0" part runs in a subshell, so "exit" exits 
that subshell (and I'm somewhat surprised that no semicolon is required after 
the closing bracket, but I may have missed something in the grammar). Try 
this:

if exit 0; then
  echo ppp
fi

-- 
D.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]