A shell script is the windows equivalent for a batch file. Script files are mainly used to automate tasks or run a series of command with out constant user interaction. There were once really famous way to run automated tasks. There are many GUI based applications that have replaced them, but they have still not lost their charm. Let us see here how to write a simple shell script file. As in all cases, let us say hello to the world..;)
1. Open a simple editor. Create a new file helloworld.sh . "sh" is the extension for shell scripts.
2. The first line in any shell script should be, #!/bin/sh . This is used to indicate to the Operating System the type of the file to be processed.
3. "echo" is a simple command that is used to print values of variables or static content on the console as output. As we wanted to say hello to the world, our second line will be echo "Hello World".
Done. Yes. We are done with our first shell script code. If I was not wrong, this is how your file would look after the code.
By Default Ubuntu (the linux variant that I am using) , does not give permission to execute all files. So let us give our file permission. In the terminal go the folder where your file is placed. It is in Desktop in my case, so I have attached the screen shot where I went into the folder and then gave permission and finally executed the shell script.
The Shell scripts can be used to automate many tasks. Also it makes you look little geeky..:) In my next blog, I will present how much I use shell scripts in my day to day operations.
1. Open a simple editor. Create a new file helloworld.sh . "sh" is the extension for shell scripts.
2. The first line in any shell script should be, #!/bin/sh . This is used to indicate to the Operating System the type of the file to be processed.
3. "echo" is a simple command that is used to print values of variables or static content on the console as output. As we wanted to say hello to the world, our second line will be echo "Hello World".
Done. Yes. We are done with our first shell script code. If I was not wrong, this is how your file would look after the code.
#!/bin/shOnce this is done, we need to invoke this file from our Terminal. So open Applications => Accessories => Terminal.
echo "Hello World"
By Default Ubuntu (the linux variant that I am using) , does not give permission to execute all files. So let us give our file permission. In the terminal go the folder where your file is placed. It is in Desktop in my case, so I have attached the screen shot where I went into the folder and then gave permission and finally executed the shell script.
The Shell scripts can be used to automate many tasks. Also it makes you look little geeky..:) In my next blog, I will present how much I use shell scripts in my day to day operations.
Add a comment