I am trying to run .hql file through a shell script like below
#!/bin/bash
cd /path/
hive -f hive_script.hql
but the script hive_script.hql is failing. I want to exit the shell script successfully even if the script fails. Is that possible?
If you don't put an explicit exit in your script, the exit code of your script would be the exit code of the last command it ran - in your case, it is the hive -f ... command.
You can add exit 0 at the end of your script to make sure it always exits with zero.
Related:
If you want the script to exit with 0 even when hive -f hive_script.hql would fail, you can just or the command with something that won't ever throw an error
hive -f hive_script.hql || :
This means that if the hive command fails, bash should also run the second command. In this case, that command is :, which is basically pass from python, and will always return a 0 status.
cd /path/ part of the command. You can also do cd /path/ || : to prevent that from failing.echo $? after running the script return a nonzero number?
exit 0. But why on earth would you want to pretend the script ran successfully?shthough your she-bang is#!/bin/bash?hive -f hive_script.hql ||:is another idiomatic way to ignore a nonzero exit status. (:is another name fortrue).cd /path/ || exit; without the|| exit, you'll try to runhivein the wrong directory if thecdfails.