shallowbit
4/10/2018 - 6:24 AM

bash arguments

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"