Are batch files possible?

Soldato
Joined
14 Oct 2007
Posts
2,738
Are batch files possible in Ubuntu?
I tried to use Gedit and saved it as .bat but im guessing that doesnt work...what extension does it need to be?
 
Shell Scripts are essentially equivalent to batch files (although much more awesome).

following sort of syntax:
Code:
#!/bin/bash
echo hellooo

And make sure you chmod +x the file to make it executable, extensions are irrelevant but .sh is the standard.

Run the script with ./myscript.sh from a terminal
 
Last edited:
Shell Scripts are essentially equivalent to batch files (although much more awesome).

following sort of syntax:
Code:
#!/bin/bash
echo hellooo

And make sure you chmod +x the file to make it executable, extensions are irrelevant but .sh is the standard.

Run the script with ./myscript.sh from a terminal

:eek: I dont know ANYTHING about Linux so what you've just said doesnt make much sense in regards to chmod +x and ./myscript.sh lol
 
Sorry.

Ok so you're using gedit. Your script (plain/simple text file) must start with the line #!/bin/bash. After that you write your commands to be executed, one on each line.

Once you're done and saved, right click on the file within Ubuntu, and go to properties and tick the 'executable' box.

From here, you should be able to double click on the file and it should execute your script.

Its worth learning to use the terminal if you want to make a more advanced script, heres a really good tutorial on shell scripts: http://www.freeos.com/guides/lsst/

Hopefully that's a little clearer
 
You're about to lean that GNU/Linux is so much better at scripting than windows that it's not funny. And that it's so much better than that that it is funny again.
 
Bash is so ubiquitous now that most people still use bash only commands in their scripts, even when the command processor is declared as sh.
 
Are batch files possible in Ubuntu?
I tried to use Gedit and saved it as .bat but im guessing that doesnt work...what extension does it need to be?

Linux and Unix based OS's are so, so, so superior to Windows when it comes to batch scripts. Shell scripts rock :)
 
Bash is so ubiquitous now that most people still use bash only commands in their scripts, even when the command processor is declared as sh.

What if it's not GNU? AIX for example, whose default is ksh (although bash is usually there too).
 
Last edited:
What is it's not GNU? AIX for example, whose default is ksh (although bash is usually there too).

To true ... I tend to write most of my scripts on AIX or HP-UX so tend to use ksh far more than other shell environments.

One thing to remember .Kencs is that Unix/Linux does not use the latter part of the filename to determine what to do with the file (although some Linux desktop environments may do things in this area with their file managers), hence your script does not need to be called ????.sh; tidy.app.logs, checksystem or start.app are all just as valid.
 
Some useful links for writing shell scripts (batch files in Windows speak):

http://tldp.org/LDP/abs/html/ - Very useful introduction to BASH scripting from a programming perspective. It assumes some basic Linux knowledge.

http://mywiki.wooledge.org/BashFAQ - When you run into more advanced problems this FAQ is fairly likely to cover them. If you are just starting out you may find it doesn't deal with your problems but that's probably because it's an FAQ aimed more at advanced stuff. BASH is a very powerful scripting language and is well documented on the Internet.
 
Back
Top Bottom