Bash · lesson 3 of 30 · First stepsRead the command line
$1 is the first argument, $# is the number of arguments and "$@" is all of them, each whole.
03-arguments.sh Download 03-arguments.sh
#!/usr/app/TurboShell/bin/bash
echo "program: ${0##*/}"
echo "count: $#"
echo "first: ${1:-none}"
for word in "$@"; do
echo "word: $word"
done
Terminal
$ bash 03-arguments.sh beach.jpg "my notes.txt"
program: 03-arguments.sh
count: 2
first: beach.jpg
word: beach.jpg
word: my notes.txt
$ bash 03-arguments.sh
program: 03-arguments.sh
count: 0
first: noneExercise
Print the last argument.