If you have ever done a lot of repetitive tasks on a Ubuntu Linux machine, I’m sure you’ve wondered if there’s a better way of doing things. For example, say I need to run a dozen or more command line commands. I could enter them in one by one or I can put them all in a single file and run it as a script.
When you run it all as a script, you save a lot of time. Today, I am going to show you how to make the most simple Ubuntu script you can find. It doesn’t use any variables, it just helps you run several commands at once. for example, we are going to create a simple script to
First, just you need to create the script file. For this just open a terminal and type:
gedit samplescript.sh
This will open gedit with a blank file named samplescript.sh. In the file, type the following:
#!/bin/sh
echo “welcome”
firefox
Save this file. The first line identifies it as a shell script, the second line causes the script to print welcome on your screen when it’s run. After the echo, you can put in any commandline line you want to on the next line and it will run. For this example, we put the command firefox and when you run the file, it will open Firefox.
Next, run this command to make the file executable:
chmod 777 samplescript.sh
Now, to run the script, type this:
./samplescript.sh
See how easy that was? We’ll come back soon and do more complex scripts, but hopefull this can save you some time now.
Tags: tutorial
4 comments ↓
hey,
thanks for the easy to follow tutorial, it helped alot. Consider I’m new to linux and still figuring it all out, this basic one was a great start
one thing: check your file names — ‘upgradescript.sh’ becomes ’samplescript.sh’.
thanks,
ben
Oops, thanks. I made the changes.
I know this is old now, but I found this via google and it was quite helpful. Like the above poster (ben), I’m new to Linux, and a BASIC tutorial of scripting was very helpful.
Thanks!
Wow, this was helpful! Seriously, I’m using Ubuntu 8.04 and this was a big help to getting me ready to do much more complex stuff. After reading this, and another equally short tutorial, I was able to convert all my m4a files in no time, whereas before I read this, it took some great deal of time.
Leave a Comment