i am facing an issue with this simple code , where i call a function , but the variable $X of that function doesnt seem to pass outside, since the printout message is always "Your interface is ." ... Am i missing something?
#! /bin/bash
function choose
{
echo -e " Choose your interface:"
echo -e " 1) WLan0"
echo -e " 2) WLan0mon"
echo -e " Choose: "
read -e X
if [ "$X" = "1" ]
then
X="wlan0"
elif [ "$X" = "2" ]
then
X="wlan0mon"
fi
}
(choose)
echo -e "Your interface is $X."
Xonly exists inside the scope of yourchoosefunction. Try either removing the function definition/call altogether, or moving theechoinside the body of thechoosefunction.