'batch' file for bash

Programming, for all ages and all languages.
Post Reply
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

'batch' file for bash

Post by suthers »

I was wondering, is it possible to get make a batch file for bash?
Thanks in advance,

Jules
User avatar
bluecode
Member
Member
Posts: 202
Joined: Wed Nov 17, 2004 12:00 am
Location: Germany
Contact:

Post by bluecode »

It's called bash script, if that is what you meant...
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post 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
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Post 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
User avatar
inx
Member
Member
Posts: 142
Joined: Wed Mar 05, 2008 12:52 am

Post 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.
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Post by suthers »

Thanks inx that did it. :D
Jules
User avatar
inx
Member
Member
Posts: 142
Joined: Wed Mar 05, 2008 12:52 am

Post by inx »

np :) Glad I could help
Post Reply