Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid a shell script exiting on failure for particular commands

Tags:

shell

sh

The following script runs with the -e option, so it will exit if any of the commands in it fail:

#!/bin/sh -e
command1 #script should fail if command1 fails
command2 #script should NOT fail if command2 fails
command3 #script should fail if command3 fails

How can I make the script not to fail on command2?

like image 537
rodee Avatar asked May 01 '14 20:05

rodee


1 Answers

command1
command2 || true
command3
like image 141
John Kugelman Avatar answered Oct 13 '22 11:10

John Kugelman