LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   grep acting strange in script (https://www.linuxquestions.org/questions/programming-9/grep-acting-strange-in-script-266303/)

fredgt 12-14-2004 10:17 AM

grep acting strange in script
 
I'm writing a for my wireless card to be able to switch easy between networks and connect to them. The script it self is working fine but after the connection i want to output a "status raport" of the network connection.
One of the things i wanted to report was the ip but as soon as i us a grep command it acts strange and doesn't give any output. I've tryed the commands themself in the shell and they all work but as soon as i try them form the script it fails


IP=`/sbin/ifconfig wlan0 | grep inet | cut -d: -f2 | cut -d' ' -f1`
echo $IP

this works in the shell but not in the script

Does anybody now why and how i can fix this.

jim mcnamara 12-14-2004 10:29 AM

It sounds like the problem is above the grep code.
stdout/stderr is being redefined or doesn't exist.

fredgt 12-14-2004 11:15 AM

OK found the problem, it has nothing to do with 'grep'.
Just a stupid mistake, is started dhcpcd but emediatly after that i tryed to get the ip but the DHCP request hasn't been completed at that time so the grep inet won't return anything.
No i first sleep for a few seconds and then i can get the ip.


All times are GMT -5. The time now is 10:37 AM.