Created
February 9, 2018 20:10
-
-
Save YakDriver/4247d1dec9db9db92493b902d20c547d to your computer and use it in GitHub Desktop.
Bash Basics: Function arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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