Hi,
How are you calling the
command2 function?
Could it be that you're confusing arguments given to the script with those given to a function?
If you run your script like this:
Code:
./script.sh one two
one and two are represented by $1 and $2 in the script, but any function in that script isn't aware of that.
A function also uses $1, $2, etc. These hold the values the function was called with.
If you use
command2 $1 $2 it will work.
Have a look at this:
Code:
#!/bin/bash
function foo() {
echo "Inside function"
echo $1
echo $2
echo $3
echo " ------------------"
}
echo "Outside function"
echo $1
echo $2
echo $3
echo " ------------------"
foo "Hello" $2 "Bye"
Run this as:
./script.sh one two three
This is one of the reasons why it is good practise to properly name your variables, it makes things more readable and also reduces the chance of mix-ups.
Hope this helps.