How to run a tcsh shell command and selectively ignore the status? How to run a tcsh shell command and selectively ignore the status? unix unix

How to run a tcsh shell command and selectively ignore the status?


I don't know about tcsh, but with bash, you can use set -e to do this. When the -e flag is set, bash will exit immediately if any subcommand fails (see the manual for technical details). When not set, it will continue to execute. So, you can do something like this:

set +ecp file/that/might/not/exist .  # Script will keep going, despite errorset -ecp file/that/might/not/exist .  # Script will exit hereecho "This line is not reached"


Here we go: Spawn a new shell, use ';' to ignore the first status, and it returns all clear.

$SHELL -c 'cp file/that/might/not/exist . ; echo "good"'


mustsucceed || exit 1mustbeignored || :