Skip to content

Bash functions and global variables #3

@Danno040

Description

@Danno040

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions