A bash script file to print welcome to the Linux

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.”

  1. Create a new file called welcome.sh, using a text editor such as vim, vi, or nano.
  2. vim welcome.sh
  3. It will open an empty file with vim editors and the file name will be welcome.sh
  4. 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
  5. Type to print the message on screen echo “Welcome to the Linux.”

Finally, the code will look like the below way.

#!/bin/bash
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,

./welcome.sh

Or use the absolute path, like below,

/root/script.sh

Output———-

Bash script output
welcome .sh script output.

Conclusion

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.

Leave a Reply

Your email address will not be published.