Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bash functions and global variables #3

Open
Danno040 opened this issue Nov 23, 2016 · 1 comment
Open

Bash functions and global variables #3

Danno040 opened this issue Nov 23, 2016 · 1 comment

Comments

@Danno040
Copy link
Contributor

Currently, there are three functions put, get, and keys in the script.

Each of them ends up mutating global state, which probably isn't a good idea in the long term. You can make your functions more "pure" by using command substitution:

function myfunc()
{
    local  myresult='some value'
    echo "$myresult"
}

result=$(myfunc)   # or result=`myfunc`
echo $result

The function keys is probably the most problematic as you're creating a function and a global variable with the same name.

@dhoer
Copy link
Owner

dhoer commented Nov 23, 2016

I like that approach. Please submit a PR and I will accept it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants