Skip to content

Instantly share code, notes, and snippets.

@rjmoggach
Last active February 6, 2018 04:52
Show Gist options
  • Select an option

  • Save rjmoggach/35017f428c702c23fe40 to your computer and use it in GitHub Desktop.

Select an option

Save rjmoggach/35017f428c702c23fe40 to your computer and use it in GitHub Desktop.
Bash Function Scope
#!/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