Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#!/bin/bash
ActivateMonitoring() {
echo -n "Enter device: "
read Device
xterm -e ifconfig $Device down
xterm -e macchanger -A $Device
xterm -e ifconfig $Device up
xterm -e airmon-ng stop $Device
xterm -e airmon-ng start $Device
echo -n "Any more[y/n]? "
read Decision
if [[ $Decision == 'y' ]]; then
{
ActivateMonitoring
}
else
echo
echo "Monitoring mode Configured"
fi
return '$device'
}
s=""
ActivateMonitoring = s
echo $s
exit 0
I am trying to get the function ActivateMonitoring to return a string, so I can use a global variable and then in return, use it as input for new functions. But, when I try by by doing ActivateMonitoring = s, I get an error of: $s: numeric argument required. And, when I try to set it as s = ActivateMonitoring, another error comes up saying s is not a function. (Obviously; Im just trying things).
why do you have a space between the "=" sign? to get the return value,
Code:
var=$(ActivateMonitoring)
I do it because it is easier to read, and I normally code in C. Bash, as I am becoming to see, can be tedious. Thanks, but either way, functions only return numerical values so the return would not have worked stopping the script before var=${ActivateMonitoring}
What does "it stops on the last bracket in Menu" mean? What are the symptoms? It would be helpful if you could also post what you see at the command prompt when you run the script.
I do it because it is easier to read, and I normally code in C. Bash, as I am becoming to see, can be tedious.
not really. you can't have spaces when you declare variables
Quote:
Thanks, but either way, functions only return numerical values so the return would not have worked stopping the script before var=${ActivateMonitoring}
not really either. Function return numerical values , true, but you can "return" strings if you like, using echo/printf and then "catching" it from main.
here's how i would do it, using infinity loop
Code:
while true
do
cat <<EOF
1) this is option 1
2) this is option 2
3) Exit
EOF
read -p "Enter your choice" choice
case "$choice"in
1) echo "do something";;
2) echo "do something";;
3) exit;;
*) echo "try again";;
esac
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.