This article covers the method of creating and running a shell script in Linux Mint 20.
With this, you can write and execute complex shell scripts in Linux Mint 20 very easily.
To write and execute a script:
1. Open the terminal. Go to the directory where you want to create your script.
2. Create a file with . sh extension.
3. Write the script in the file using an editor.
4. Make the script executable with command chmod +x <fileName>.
5. Run the script using ./<fileName>.
To save a .sh file in Ubuntu:
1. Run nano hello.sh.
2. nano should open up and present an empty file for you to work in.
3. Then press Ctrl-X on your keyboard to Exit nano.
4. nano will ask you if you want to save the modified file.
5. nano will then confirm if you want to save to the file named hello.sh.
To Make a Bash Script Executable in Linux:
1) Create a new text file with a . sh extension.
2) Add #!/bin/bash to the top of it. This is necessary for the “make it executable” part.
3) Add lines that you'd normally type at the command line.
4) At the command line, run chmod u+x YourScriptFileName.sh.
5) Run it whenever you need!