I'm not an expert about programming sh script and I run in trouble when I try to understand what happens in a big shell script (like portmaster). What I wish to do is writing functions with writable variables in parameters. I make an example:
I hope this example explain what I was say. Executing it give the result:
Bash:
#! /bin/sh
varResult=0
# Add two numbers and put result in a variable (by reference)
# Params:
# $1 first number
# $2 second number
# $3 [ref] result
addFunc ()
{
local num1 num2 result
if [ "$#" -ne "3" ]; then
echo "wrong params"
return 1
fi
num1=$1
num2=$2
result=$3
$result=$(( num1 + num2 ))
return 0
}
# Main
addFunc "6" "4" "varResult"
echo "6 + 4 = $varResult"
I hope this example explain what I was say. Executing it give the result:
Code:
/root/bin/test.sh: varResult=10: not found
6 + 4 = 0