Skip to content

Instantly share code, notes, and snippets.

@YakDriver
Created February 9, 2018 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YakDriver/4247d1dec9db9db92493b902d20c547d to your computer and use it in GitHub Desktop.
Save YakDriver/4247d1dec9db9db92493b902d20c547d to your computer and use it in GitHub Desktop.
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