Created
February 5, 2024 12:17
-
-
Save ruslo/09b3e10a21522d43c354d5eb6299f22d to your computer and use it in GitHub Desktop.
Template bash script file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Exit immediately if command returns a non-zero status. | |
# Do not move it to shebang since it will be ignored | |
# if run by "/bin/bash ./bash_script.sh" | |
set -e | |
# No arguments are expected, so exit with an error if anything is provided | |
# https://unix.stackexchange.com/a/25947 | |
if [ ! $# -eq 0 ]; | |
then | |
echo "Unexpected arguments: '$*'" | |
exit 1 | |
fi | |
# Self location helper variables | |
# https://stackoverflow.com/a/68359914 | |
THIS_SCRIPT_PATH="${BASH_SOURCE:-$0}" | |
THIS_SCRIPT_DIR="`dirname "${THIS_SCRIPT_PATH}"`" | |
# Sanity check | |
# Note: | |
# If it's a symbolic link, it will only work | |
# if the symbolic link name is the same | |
EXPECTED_FILE="${THIS_SCRIPT_DIR}/bash_script.sh" | |
if [ ! -r "${EXPECTED_FILE}" ]; | |
then | |
echo "File not found: ${EXPECTED_FILE}" | |
exit 1 | |
fi | |
echo "Hello, world!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment