Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I use set -e to stop bash script on first errorstop bash script on first error.

All work OK unless I use command with &&:

$ cat script
set -e
cd not_existing_dir && echo 123
echo "I'm running! =P"
$
$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
I'm running! =P
$

compared with:

$ cat script
set -e
cd not_existing_dir
echo "I'm running! =P"
$
$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
$

The first example still echoes I'm running!, but the second one doesn't. Why do they behave differently?

UPD. Similar question: http://stackoverflow.com/questions/6930295/set-e-and-short-testshttps://stackoverflow.com/questions/6930295/set-e-and-short-tests

I use set -e to stop bash script on first error.

All work OK unless I use command with &&:

$ cat script
set -e
cd not_existing_dir && echo 123
echo "I'm running! =P"
$
$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
I'm running! =P
$

compared with:

$ cat script
set -e
cd not_existing_dir
echo "I'm running! =P"
$
$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
$

The first example still echoes I'm running!, but the second one doesn't. Why do they behave differently?

UPD. Similar question: http://stackoverflow.com/questions/6930295/set-e-and-short-tests

I use set -e to stop bash script on first error.

All work OK unless I use command with &&:

$ cat script
set -e
cd not_existing_dir && echo 123
echo "I'm running! =P"
$
$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
I'm running! =P
$

compared with:

$ cat script
set -e
cd not_existing_dir
echo "I'm running! =P"
$
$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
$

The first example still echoes I'm running!, but the second one doesn't. Why do they behave differently?

UPD. Similar question: https://stackoverflow.com/questions/6930295/set-e-and-short-tests

Change examples order to be more readable
Source Link

I use set -e to stop bash script on first error.

All work OK unless I use command with &&:

$ cat script
set -e
cd not_existing_dir && echo 123
echo "I'm running! =P"
$
$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
I'm running! =P
$

compared with:

$ cat script
set -e
cd not_existing_dir && echo 123
echo "I'm running! =P"

compared with:

$
$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
$ cat script
set -e
cd not_existing_dir
echo "I'm running! =P"

The first example still echoes I'm running!, but the second one doesn't. Why do they behave differently?

UPD. Similar question: http://stackoverflow.com/questions/6930295/set-e-and-short-tests

I use set -e to stop bash script on first error.

All work OK unless I use command with &&:

$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
I'm running! =P
$ cat script
set -e
cd not_existing_dir && echo 123
echo "I'm running! =P"

compared with:

$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
$ cat script
set -e
cd not_existing_dir
echo "I'm running! =P"

The first example still echoes I'm running!, but the second one doesn't. Why do they behave differently?

UPD. Similar question: http://stackoverflow.com/questions/6930295/set-e-and-short-tests

I use set -e to stop bash script on first error.

All work OK unless I use command with &&:

$ cat script
set -e
cd not_existing_dir && echo 123
echo "I'm running! =P"
$
$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
I'm running! =P
$

compared with:

$ cat script
set -e
cd not_existing_dir
echo "I'm running! =P"
$
$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
$

The first example still echoes I'm running!, but the second one doesn't. Why do they behave differently?

UPD. Similar question: http://stackoverflow.com/questions/6930295/set-e-and-short-tests

Tweeted twitter.com/StackUnix/status/780758441812000768
Add link to a similar question
Source Link

I use set -e to stop bash script on first error.

All work OK unless I use command with &&:

$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
I'm running! =P
$ cat script
set -e
cd not_existing_dir && echo 123
echo "I'm running! =P"

compared with:

$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
$ cat script
set -e
cd not_existing_dir
echo "I'm running! =P"

The first example still echoes I'm running!, but the second one doesn't. Why do they behave differently?

UPD. Similar question: http://stackoverflow.com/questions/6930295/set-e-and-short-tests

I use set -e to stop bash script on first error.

All work OK unless I use command with &&:

$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
I'm running! =P
$ cat script
set -e
cd not_existing_dir && echo 123
echo "I'm running! =P"

compared with:

$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
$ cat script
set -e
cd not_existing_dir
echo "I'm running! =P"

The first example still echoes I'm running!, but the second one doesn't. Why do they behave differently?

I use set -e to stop bash script on first error.

All work OK unless I use command with &&:

$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
I'm running! =P
$ cat script
set -e
cd not_existing_dir && echo 123
echo "I'm running! =P"

compared with:

$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
$ cat script
set -e
cd not_existing_dir
echo "I'm running! =P"

The first example still echoes I'm running!, but the second one doesn't. Why do they behave differently?

UPD. Similar question: http://stackoverflow.com/questions/6930295/set-e-and-short-tests

edited tags
Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420
Loading
Clarify the question
Source Link
Loading
Add tags
Link
Loading
Source Link
Loading