Page 1 of 1

'batch' file for bash

Posted: Sat Apr 19, 2008 7:37 am
by suthers
I was wondering, is it possible to get make a batch file for bash?
Thanks in advance,

Jules

Posted: Sat Apr 19, 2008 7:39 am
by bluecode
It's called bash script, if that is what you meant...

Posted: Sat Apr 19, 2008 9:00 am
by Brynet-Inc
..or the more "vendor-neutral" term, a Shell Script. 8)

http://en.wikipedia.org/wiki/Unix_shell
http://en.wikipedia.org/wiki/Shell_script

Posted: Sat Apr 19, 2008 2:29 pm
by JamesM
Have you tried?

just doing

Code: Select all

my command1
my command2
inside a file then

Code: Select all

sh myfile
Will do the same as a batch file.

If you want to be better, add this at the top of your file:

Code: Select all

#!/bin/sh
then,

Code: Select all

chmod u+x myfile
Then you can just run it:

Code: Select all

./myfile

Posted: Sat Apr 19, 2008 2:50 pm
by suthers
I tried using sh to execute a script but it always says command not found, does it need a different script from what i would normally use in bash?
Thanks in advance,

Jules

Posted: Sat Apr 19, 2008 3:03 pm
by inx
suthers wrote:I tried using sh to execute a script but it always says command not found
If you're not doing anything terribly complex, you won't need a different script for sh than bash. On a lot of Linux distributions, /bin/sh is linked to bash, anyway.

There's two possibilities for why you get a command not found on sh:
1) You're using MSYS or Cygwin and there is no special treatment of the scripting shell, so no sh link.
2) You're using an odd distribution that stuffed sh in /sbin and didn't include /sbin in your path.

In either case, just use bash instead of sh in the invocation.

Posted: Tue Apr 22, 2008 10:37 am
by suthers
Thanks inx that did it. :D
Jules

Posted: Wed Apr 23, 2008 4:11 pm
by inx
np :) Glad I could help