Last active
February 6, 2018 04:52
-
-
Save rjmoggach/35017f428c702c23fe40 to your computer and use it in GitHub Desktop.
Bash Function Scope
This file contains hidden or 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/env bash | |
| ARG01="moderately $1" | |
| ARG02="seriously $2" | |
| sanity_check() { | |
| local you=$1 | |
| local me=$2 | |
| echo "You are $you" | |
| echo "I am $me" | |
| } | |
| echo ARG01: $1 | |
| echo ARG02: $2 | |
| # this won't work... | |
| sanity_check $ARG01 $ARG02 | |
| # you need to quote your arguments | |
| sanity_check "$ARG01" "$ARG02" | |
| sanity_check attractive ugly | |
| # OUTPUT of `bashScope.sh crazy mad` | |
| # ARG01: crazy | |
| # ARG02: mad | |
| # You are moderately | |
| # I am crazy | |
| # You are moderately crazy | |
| # I am seriously mad | |
| # You are attractive | |
| # I am ugly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment