help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Is there a way to pass by reference?


From: Peng Yu
Subject: [Help-bash] Is there a way to pass by reference?
Date: Wed, 12 Dec 2018 14:38:33 -0600

Hi,

I am wondering if there is a way to do pass by reference in a bash
function. For example, I'd like `f` to do something like this. Is this
possible in bash? Thanks.

function f {
# do something to the variable referred by $1
}

declare x
f x
echo "$x" # x should have the value set by f.

function g {
declare x
f x # It should work for local variables as well.
echo "$x" # x should have the value set by f.
}

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]