hi
i have a function
abc()
{
a=1
b=2
c=3
}
Now i want to assign these values to the variables out side the function
k=a
l=b
m=c
please help
hi
i have a function
abc()
{
a=1
b=2
c=3
}
Now i want to assign these values to the variables out side the function
k=a
l=b
m=c
please help
Variables have global scope, unless explicitly declared local inside a function.
You need to interpolate the values that you assign, though.
k=$a
l=$b
m=$c
abc()
{
a=1
b=2
c=3
echo "k=$a \n l=$b \n m=$c"
}
eval $(abc)
echo "outside fn $k"
echo "outside fn $l"
echo "outside fn $m"
Included in a script and run, I get the following output
outside fn
outside fn
outside fn
Works here (although I would perhaps have done it differently); which shell are you using?
bash$ cat jredx
#!/bin/sh
abc()
{
a=1
b=2
c=3
echo "k=$a \n l=$b \n m=$c"
}
eval $(abc)
echo "outside fn $k"
echo "outside fn $l"
echo "outside fn $m"
vnix$ ./jredx
outside fn 1
outside fn 2
outside fn 3