![]() |
Re: [Linux bash] Why is this not working?
Quote:
|
Re: [Linux bash] Why is this not working?
Quote:
Here : Code:
Nokia-N900-02-8:/etc/network# vi detectUsb.test.sh |
Re: [Linux bash] Why is this not working?
Quote:
1. I didn't know It's an option. 2. There are plenty of scripts on the phone that manage without bash, i'd like to manage without it as well. 3. The less apps on my phone the better. (if I can deal without them ofc). |
Re: [Linux bash] Why is this not working?
Yep, * has its wildcard characteristic only by certain interpreters. Bash interprets it as gobuki described, as long as it's actually interpreted by bash (i.e. not escaped e.g. by \ or ''). Compare
echo *b* and echo "*b*" in bash with some file with b in its name in the same directory. Thus, fiddeling with * with some tools like find ... -regex ... -exec ... can be quite tricky in escaping "enough" to avoid bash interpreting it in the first step but have find interpret it for -regex but not for -exec which shall pass it to the next level of bash.........;°)) For sed and numerous other tools * is the "any number of" operator used in regular expressions ( ab*c). Test (or the short form [...]) does not interpret or compare any regular expressions, if using = (single = is the "official" documented version but == works, too) but rather compares the strings literally. If you want some regex functionality, try this: my="abcd" if [ `echo $my | grep bc` ] then echo "Ok" else echo "Not ok" fi Good luck! |
Re: [Linux bash] Why is this not working?
Not sure if this is the *best* way to do it but it does seem to work on my N900:
Quote:
|
Re: [Linux bash] Why is this not working?
Quote:
The example you posted works well, but when I tried to adapt it a bit to my needs, I have an odd error : Code:
Nokia-N900-02-8:/etc/network# vi detectUsb.sh I am a big bash / sh noob. |
Re: [Linux bash] Why is this not working?
If you only want to check, whether it is running or not, you could do
if `echo $my | grep -q RUNNING` Note: no "test" or [...]. grep -q is "quiet" and gives a return value for "found" or "not found" |
Re: [Linux bash] Why is this not working?
Quote:
|
Re: [Linux bash] Why is this not working?
Forgot to mention: This only works for
my=`/sbin/ifconfig usb0` otherwise it would be true if *any* network adapter is RUNNING, as all lines are parsed by grep and it would find some line with RUNNING ;°) So, this complete code must work: #!/bin/sh if `/sbin/ifconfig usb0 2>/dev/null | grep -q RUNNING` then echo "Ok" else echo "Not ok" fi if you replace usb0 by $1 as command line argument, you can use it for any network interface. |
Re: [Linux bash] Why is this not working?
Quote:
I think the error you made is you are testing the output of grep and not its return value that is in $? after grepping. |
All times are GMT. The time now is 12:39. |
vBulletin® Version 3.8.8