81
Steps to write and execute a script
- Open the terminal. Go to the directory where you want to create your script.
- Create a file with .sh extension.
- Write the script in the file using an editor.
- Make the script executable with command chmod +x <fileName>.
- Run the script using ./<fileName>.
Note: In the last step you have to mention the path of the script if your script is in other directory.
Hello World script
Here we’ll write a simple programme for Hello World.
First of all, create a simple script in any editor or with echo. Then we’ll make it executable with chmod +x command. To find the script you have to type the script path for the shell.
Look at the above snapshot, script echo Hello World is created with echo command as hello_world. Now command chmod +x hello_world is passed to make it executable. We have given the command ./hello_world to mention the hello_world path. And output is displayed.
Next TopicScript Parameters