#!/bin/bash

# scope1.sh
# playing with scope of function "parameters" and shell script
#     command line arguments!
#
# by: Sharon Tuttle
# last modified: 2022-11-16

# function: myfunct
# a little function that reports its arguments
#     to the screen -- especially its first argument --
#     and changes variable x to 2

myfunct()
{
    echo "myfunct was called with: $@"
    echo "in myfunct, \$1 is: $1"
    x=2
}

### main script starts here

echo "$0 was called with: $@"
echo "in $0, \$1 is: $1"
x=1
echo "x is: $x"
myfunct 1 2 3

# so, yes, if you change a variable in a function,
#    (that's running in the same shell), that
#    will change it in the calling script, also

echo "x is now: $x"

# BUT note: piping something evidently opens
#    a new subshell...?

x=133333
myfunct 1 2 3 | tee out.log
echo "x is now: $x"