Okay, so im setting up a script to start my internet dependent scripts once I am connected to the net. It got complicated because of the different networks I frequent but it goes something like this:
n=1
iwconfig wlan0 > wireless.txt
m= grep -c MGHS /home/jake/Scripts/wireless.txt
o= grep -c NMU /home/jake/Scripts/wireless.txt
while [ $n -le 50 ]; do
echo $n & sleep 3
let n++
if (ping -c 1 www.google.com)
then sh /home/jake/Scripts/netdepsu.sh
elif test "$m" -ne "0"
then sh /home/jake/Scripts/netdepsu.sh
elif test $o -ne $0
then sh /home/jake/Scripts/netdepsu.sh
else echo "no internet"
fi
done
Basically, if that txt file contains the name of one of the weird networks I use then I want to start up the other script (i cant ping at NMU or MGHS). Here are the two errors I just cant get rid of:
./looper.sh: line 13: test: : integer expression expected
./looper.sh: line 15: test: -ne: unary operator expected
if I dont have that space after those '='s up top then I get this error:
./looper.sh: line 6: -c: command not found
./looper.sh: line 7: -c: command not found
I know this has to be an easy fix if anyone could let me know I'd be ever so grateful....
Those are grave accents (ASCII 96), not regular straight apostrophes.
In other news, the parentheses around the ping in the if are superfluous, and the & you use in a few places means "background this process"; you want "&&" which means "and if the previous command was successful, also run ..." or perhaps just semicolon, which is basically equivalent to newline.
This assigns "bar" to the variable "foo" for the duration of the execution of the command echo boink
To assign a variable value which contains spaces, you want
foo='bar echo boink'
There are differences between single and double quotes but in this context, both work equally well. I suspect it's better to save explaining the difference until another time.