Skip to main content
edited tags; edited tags
Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Source Link
Pablo
  • 177
  • 8

Function can echo the value that has not received as input

I'm new to bash. I'm confused about the way functions work in this language.

I have written this code:

#!/usr/bin/env sh

choice_func() {
        echo "$choice"
}

echo "Enter your choice:"
read choice
choice_func

While investigating my code, I realized that I have forgotten to send the value of choice as input when calling choice_func(). But it works properly! how it is possible that the function has not been given the input but can echo it?