Created
December 12, 2017 10:18
-
-
Save bsnape/4ebea089aff6d20d880a2785412df689 to your computer and use it in GitHub Desktop.
bash arguments
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
#!/usr/bin/env bash | |
set -x | |
set -e | |
if [ $# -eq 0 ]; then | |
echo "Received no arguments. Exiting..." | |
exit | |
fi | |
# $@ is one-based and not zero-based | |
echo "got arguments: $@" | |
echo "--------" | |
for arg in "$@" | |
do | |
echo "arg: $arg" | |
done | |
echo "--------" | |
echo "\$0: $0" # $0 is the name of the shell or shell script | |
echo "\$1: $1" # $1 is the first argument | |
echo "\$2: $2" # $2 is the second argument | |
echo "\$3: $3" # etc | |
echo "\$4: $4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment