![]() |
[Linux bash] Why is this not working?
I've been at this for 3 hours now.
It's not wrorking. Code:
#!/bin/sh I ran this on my phone using putty. On the other hand : this works : Code:
#!/bin/sh |
Re: [Linux bash] Why is this not working?
I didn't know that * is working like that with strings. Is it? It's expanded to filesystem objects names in bash.
If you are sure this should work. How about using #!/bin/bash? :-) |
Re: [Linux bash] Why is this not working?
As far as I know, glob works with == yes,
But, there is no bash on the N900, busybox.... |
Re: [Linux bash] Why is this not working?
Code:
#!/bin/sh |
Re: [Linux bash] Why is this not working?
Quote:
The thing that is not working is the * (asterisks). What I am ultimately trying to do is check if usb0 is RUNNING. |
Re: [Linux bash] Why is this not working?
PHP Code:
|
Re: [Linux bash] Why is this not working?
Quote:
|
Re: [Linux bash] Why is this not working?
Comparing strings like this is a form of regex which requires you use double square brackets around it: if [[ ]]
|
Re: [Linux bash] Why is this not working?
The point is, look at the difference between that and your code. The point isn't "do you have bash on your N900". I don't either.
|
Re: [Linux bash] Why is this not working?
Oops.. I forgot the double brackets.
I knew the lack of quotes on the *bc* though... ;) |
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. |
Re: [Linux bash] Why is this not working?
try
Code:
if /sbin/ifconfig usb0 > /dev/null 2>&1 |
Re: [Linux bash] Why is this not working?
Quote:
Code:
if [ "${my#*bc}" != "$my" ] |
Re: [Linux bash] Why is this not working?
Quote:
You should really install a shell with better scripting support if you need regex and follow the countless shell-scripting tutorials on the net - unless maybe you want to deploy it elsewhere. Just make sure you're reading a tutorial for the right shell, since shell scripting != shell scripting. |
Re: [Linux bash] Why is this not working?
Quote:
|
Re: [Linux bash] Why is this not working?
You are right! I tried it and it works. I'm sorry. But I wonder where this is documented. I had a look at busybox.net and couldn't find anything about scripting or regular expressions. Not even in the manual page: http://busybox.net/downloads/BusyBox.html
Care to give a keyword or link? |
Re: [Linux bash] Why is this not working?
the shell built into busybox is the "Almquist shell" (or, more precisely, the debian ash variant.)
your best bet for documentation would probably be this, that's the posix documentation for -compatible shells. |
Re: [Linux bash] Why is this not working?
If you run linux on your PC and ash is installed:
> man ash contains all of it. Unfortunately man and manpages are not preinstalled on N900 :°( |
All times are GMT. The time now is 12:41. |
vBulletin® Version 3.8.8