What is bash? What is bash scripting?
If you are a Linux engineer, this is very good to know bash scripting. It is powerful and extremely useful. You can use it to handle many processes very easily with the help of it. It is a command-line interface to interact with the operating system. All the commands which you can run through the command-line, you can use that in bash scripting. Scripts are a collection of commands. BASH stands for Bourne-Again SHell. Bash is available by default on Mac and Linux.
Creating a bash file to print the message “Welcome to the Linux.”
- Create a new file called welcome.sh, using a text editor such as vim, vi, or nano.
- vim welcome.sh
- It will open an empty file with vim editors and the file name will be welcome.sh
- Type the first line which always starts with #! (hash and exclamation mark) and there is no space between # and ! this first line is known as shebang, sha-bang, hashbang, pound-bang, or hash-pling. and then put /bin/bash
- Type to print the message on screen echo “Welcome to the Linux.”
Finally, the code will look like the below way.
echo “Welcome to the Linux.”
Save the above file after pressing the Esc key and then typing:wq
After saving the file, permit to execute it, you can use the below command syntax for that. or to read more about permission you can go to the link Basic Permission
To permit the current user
chmod u+x welcome.sh
To permit all the users
chmod +x welcome.sh
As permission has been done, now run the script,
To run the script, there is some way to do it, use the ./ before the script name like below,
Or use the absolute path, like below,
In this tutorial, we will learn to create a simple welcome bash script. I hope, you understand but if you have any questions, you can ask in the comment section.