How to create a shell script in Linux?
To create a Linux shell script, you can follow these steps:
- Open a text editor, such as vi or nano.
- Start the script in a bash shell.
- Write the commands and logic for the script in the following lines.
- Save the document and exit the text editor.
- Give execute permission to the script.sh file.
- Can you provide the script file named script.sh?
- Run the script named script.sh.
Here is a simple example script that will print “Hello, World!” to the terminal.
#!/bin/bash
echo "Hello, World!"
Create a file called hello.sh, paste the above content into the file, save and close the text editor. Then add executable permission to the script using chmod +x hello.sh. Finally, run the script using the command ./hello.sh, and you should see “Hello, World!” output on the terminal.