Skip to content

Instantly share code, notes, and snippets.

@bsnape
Created December 12, 2017 10:18
Show Gist options
  • Save bsnape/4ebea089aff6d20d880a2785412df689 to your computer and use it in GitHub Desktop.
Save bsnape/4ebea089aff6d20d880a2785412df689 to your computer and use it in GitHub Desktop.
bash arguments
#!/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