# Transfer commands in argumets of function - advantage or disadvantage?



## setevoy (Oct 26, 2013)

We have this script. In many places functions are used for user confirmation before action.

It looks like:


```
function answer ()
{
while read response; do
echo
case $response in
    [yY][eE][sS]|[yY])
        $1
        $2
        break
        ;;
    [nN][oO]|[nN])
        $3
        $4
        break
        ;;
        *)
        printf "Please, enter Y(yes) or N(no)! "
esac
done
}
```

Now, in that very script there is a question:


```
[printf "Proceed? [Y/n] "
```

And then - calling function with arguments:


```
answer "$after_version_check_yes" "" "$after_version_check_no" "$after_version_check_exit"
```

The content of the arguments is stored in variables and it looks like:


```
after_version_check_yes="printf Proceeding...\n\n"
after_version_check_no="printf Exiting...\n\n"
after_version_check_exit="exit 1"
```

There are also "unsafe" commands like `break 3` or:


```
tomcat_status_kill=". $BASEDIR/bin/NG/tom_kill.sh"
```

And then tom_kill.sh runs `kill PID`.

Here is a question: is it an advantage or a disadvantage? Are there some "security" issues using that scheme?


----------

