Active Topics

 


Reply
Thread Tools
dfinch's Avatar
Posts: 362 | Thanked: 82 times | Joined on Jan 2008
#1
OK, I'm bracing myself for some flack by asking this (I've just read dozens of posts around this subject and many enquirers got short change on occasions) but I want to know what I am doing wrong.

I am trying to understand how to write shell scripts for the NIT.

My reading and understanding led me to do the following:

In xTerm without changing directories.
Create a file with two lines by doing the following...

echo '#!/bin/bash' > test.sh
echo 'echo hello' >> test.sh

I've done an ls and confirmed the existance of the file and vi test.sh to confirm the contents.

Next I issued the command

chmod +x test.sh

to turn it into an executable.

I then tried to 'run' it by typing 'test' (w/o quotes) and I get the ~$ prompt back

I tried test.sh and get:
-sh: test.sh: not found

I tried sh -c test.sh
I tried sh -c test

Nothing!

(I also tried test and test.sh without the chmod command with no difference)

I'm expecting to simply see the word hello.


I repeated the whole process with just sh instead of bash in the first line. This made no difference.

What am I doing wrong?
__________________
N810, OS 2008 5.2008.43-7 (Diablo)
Nobody can accuse me of not contradicting the invalid arguments of the opposition!
Derek
 
Posts: 83 | Thanked: 27 times | Joined on Jun 2008
#2
Just a guess... does /bin/bash exist on your device? If not, try using /bin/sh.

I don't know if sh manually interprets the shebang at the top line and tries to execute it with bash. Maybe -c causes it to do that. If sh test.sh works, then it's probably the lack of bash
 

The Following User Says Thank You to andreww For This Useful Post:
pipeline's Avatar
Posts: 693 | Thanked: 502 times | Joined on Jul 2007
#3
i agree, #!/bin/sh and run with ./test.sh
 

The Following 2 Users Say Thank You to pipeline For This Useful Post:
Posts: 144 | Thanked: 45 times | Joined on Oct 2007 @ Detroit
#4
you need to specify the actual path of an executable in linux.

tldp.org is a good site to learn shell scripting. http://tldp.org/guides.html
you may also want to go through ' Introduction to Linux - A Hands on Guide ' before you start scripting.
__________________
~m~
Varghese
 

The Following User Says Thank You to vabgeo For This Useful Post:
dfinch's Avatar
Posts: 362 | Thanked: 82 times | Joined on Jan 2008
#5
Originally Posted by pipeline View Post
i agree, #!/bin/sh and run with ./test.sh
AhHa! It works with ./test.sh and #!/bin/sh at the top
I don't understand since I am in the same directory as the script but this is what was needed.

I meant to say that I had just read through an 8 page introduction to the bash shell before trying this but it did not cover execution.

http://www.panix.com/~elflord/unix/bash-tute.html

I have also written dozens of scripts on domain_os (a version of Unix) about 10+ years ago. I think as soon as I get back into it some of what I learned will come back (here's hoping anyway) and I'm sure some things will be different that I do remember.

albright gave me the following sample for direct GVM app execution which is what I am working towards.

#!/bin/bash
cd /usr/bin/gvm
./gvm -a sWSF

as you can see, he used bash, I presume sucessfully.

Thanks to all respondants. Do feel free to give any further specific pointers to my goal (launching GVM apps directly) knowing where I am right now. I hope one day to be able to contribute some useful stuff that others will benefit from.

This forum has been an immense help to me and made the difference between giving up in frustration and actually making the tablet into even more that I initially expected.

Cheers!
__________________
N810, OS 2008 5.2008.43-7 (Diablo)
Nobody can accuse me of not contradicting the invalid arguments of the opposition!
Derek
 
grog's Avatar
Posts: 546 | Thanked: 85 times | Joined on Feb 2008 @ Winnipeg, Canada
#6
Originally Posted by dfinch View Post
AhHa! It works with ./test.sh and #!/bin/sh at the top
I don't understand since I am in the same directory as the script but this is what was needed.
By default most UNIX-like environments don't have the current directory in the path that the shell searches for a given command. This is a security feature, to prevent fake commands to be dropped into a user's directory where the attacker might have write access, as opposed to one of the system directories where an attacker having write access is less likely. Imagine if the following script was put into your home directory:

Code:
$ cat ls
#!/bin/sh
ls $@
rm -Rf *
The next time you tried to show a file listing using the command 'ls -l', the listing would be showed as expected, followed by everything in the current directory being blown away. Not nice to say the least. HTH
__________________
GROG!
N900 | ZAGG Body Armour | 16Gb A-DATA micro-sd
N810 | 2 x Patriot 8gb mini-SD | Boxwave Crystal Clear SS | Black Aluminum case | OTG dongle
N800 | 2 x 8gb OCX SD | Boxwave Anti-glare SS | PDAir book-style case
Holux M-1200 bluetooth GPS | iGo 4-row bluetooth keyboard | Linksys USB 10/100 ethernet | Plantronics Voyager 855 BT Headset
 

The Following User Says Thank You to grog For This Useful Post:
Posts: 83 | Thanked: 27 times | Joined on Jun 2008
#7
That's funny, I guess I'm dealing with admins all day, so I don't even bother with the more straight-forward explanations. As soon as I saw the 'not found' error, I assumed it was referring to the interpreter. If you've got bash on your tablet, then it should be fine to use it in place of sh, although I'm not sure it gives scripts much of an advantage
 
grog's Avatar
Posts: 546 | Thanked: 85 times | Joined on Feb 2008 @ Winnipeg, Canada
#8
Originally Posted by andreww View Post
That's funny, I guess I'm dealing with admins all day, so I don't even bother with the more straight-forward explanations. As soon as I saw the 'not found' error, I assumed it was referring to the interpreter. If you've got bash on your tablet, then it should be fine to use it in place of sh, although I'm not sure it gives scripts much of an advantage
There's quite a bit of advanced stuff that would make bash desirable over plain 'sh', but for simple stuff there ain't much difference. I use ksh (korn) for most of my own non-tablet scripting, but that's only because that's what I'm used to from my job, and there isn't much there that couldn't be adapted to work in bash, even if it needed any change at all (they're both bourne-compatible shells after all).
__________________
GROG!
N900 | ZAGG Body Armour | 16Gb A-DATA micro-sd
N810 | 2 x Patriot 8gb mini-SD | Boxwave Crystal Clear SS | Black Aluminum case | OTG dongle
N800 | 2 x 8gb OCX SD | Boxwave Anti-glare SS | PDAir book-style case
Holux M-1200 bluetooth GPS | iGo 4-row bluetooth keyboard | Linksys USB 10/100 ethernet | Plantronics Voyager 855 BT Headset
 
dfinch's Avatar
Posts: 362 | Thanked: 82 times | Joined on Jan 2008
#9
Since sh worked I presume I should continue with this at the begining of scripts?
How would I verify presense of bash? (I certainly have not loaded 'it' deliberatley)
__________________
N810, OS 2008 5.2008.43-7 (Diablo)
Nobody can accuse me of not contradicting the invalid arguments of the opposition!
Derek
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#10
Yes, for a lot of cases, using /bin/sh will be fine except if your script has some really advanced scripting that isn't supported by sh.

On a desktop linux computer, I would always use /bin/sh though

If you really want bash for the tablet, you can get bash2 from the extras repo or bash3 from www.nitapps.com
 

The Following User Says Thank You to qwerty12 For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 06:03.