I have a following script which checks whether a python module is installed or not.
{
ipython -c 'from package import module' && echo "Successful import"
} || echo "package not found!"
This is a typlical try..catch
syntax of bash. If the command before && would work it will execute the command after that otherwise execute the command after ||.
But in this case, whether package
is installed or not, or should I say whether the command
ipython -c 'from package import module'
returns None
or ImportError
, bash reads it as successful execution and prints "Successful import"
How can I check for a successful import of a python package using bash?
EDIT : And return with exit status 1?