Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash Basics: Function arguments
#!/bin/bash
# Demonstrates the use of shift and $@ mainly. Function arguments can also be accessed with $1, $2, $3, etc.
#
# ##fun1
# aaa
# ##fun2
# bbb
# ##fun3
# (# of arguments: 3)
# ccc
# Left over: ddd eee
# Left over: ddd eee
#
fun3(){
echo "##fun3"
echo "(# of arguments: $#)"
echo $1 ; shift ; echo Left over: $@ ; echo Left over: $*
}
fun2(){
echo "##fun2"
echo $1 ; shift ; fun3 $@
}
fun1(){
echo "##fun1"
echo $1 ; shift ; fun2 $@
}
fun1 aaa bbb ccc ddd eee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment