unix4artists/bash/arguments.sh

22 lines
614 B
Bash
Raw Normal View History

2021-05-08 16:53:26 +00:00
#!/bin/bash -e
#####################################################
#
# Arguments are provided to commands and scripts usually
# separated by a space. They can be read and used within
# bash scripts by referencing them with the "$#" notation.
#
# Usage: bash bash/arguments.sh <first> <second> <third> <etc>
#
#####################################################
echo "You entered \"$1\" as the first argument"
# Using a slightly different notation
if [ "${2}" != "" ]; then
echo "You entered \"${2}\" as the second argument"
fi
if [ "${3}" != "" ]; then
echo "All of the arguments you entered \"${@}\""
fi