Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a way to create and execute a script file in Ubuntu 14.04? Perhaps something like Windows batch files. Specifically, I mean the default scripting language of the Ubuntu terminal (Bash). How do you make a text file containing bash commands which will be run by the Ubuntu terminal from the top of the file to the bottom.

share|improve this question

closed as too broad by Lucio, bodhi.zazen, darent, Braiam, chaskes May 24 at 0:23

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Of course, most people use bash scripts, but you can use perl, python, awk ... See linuxcommand.org/lc3_writing_shell_scripts.php –  bodhi.zazen May 23 at 22:15

1 Answer 1

up vote 2 down vote accepted

Your "shell" or the command line interface is called bash. You can write a bash script which is similar to a batch file. A bash script starts with a She-bang #!/bin/bash and is nothing more then a set of commands to run in a sequence to run them. You are not limited to bash command, you can call any binary on the system by using the full path to the binary or script.

A master thread on learning/books/terminal/bash/Linux etc Linux Command Line Learning Resources - cortman https://help.ubuntu.com/community/CommandLineResources

My first bash was several commands I was running multiple times in terminal. So I listed history with history command and copied them into text file. First line must be this (no spaces before it and first line):

#!/bin/bash

And after saving you must make it executeable.

sudo chmod +x <path>
sudo chmod 755 <filename>

Note that it is a good idea to put your scripts in one place, so you can run them without requiring a path. If you create a bin directory in your home ( mkdir ~/bin ) the next time you login, that will automatically be included in your PATH.

mkdir ~/bin
chmod 755 ~/bin

Edit : If you want the script to be available to all users, place it in /usr/local/bin and have it owned by root with rx access by others sudo chown root:root /usr/local/bin/your_script ; sudo chmod 655 /usr/local/bin/your_script

gksudo gedit ~/.bashrc

Add the following to the end of .bashrc and save:

if [ -d $HOME/bin ]; then
PATH=$PATH:$HOME/bin
fi
share|improve this answer
    
@Strato1 bash scripts are most common, but Lucio raises a very valid point, one can use a long list of languages. They syntax is the same, start with a She-bang and list commands. Careful how you google search She-bang ;) en.wikipedia.org/wiki/Shebang_%28Unix%29 –  bodhi.zazen May 23 at 22:34
    
I do mean Bash scripts. I have updated my question to be more specific. –  Strato1 May 24 at 1:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.