Javatpoint Logo
Javatpoint Logo

Hello World! Bash Script

As per the discussion in previous topics, let's move to create a first and basic Bash Script by using the given steps:

Step 1: Open the terminal. Navigate the desktop folder or directory using the cd command.

Step 2: Create an empty file as a shell script using touch command and name it as bash_script.sh to execute. In the below image, you can see the created file with all the permission attributes in the darkened row.

Hello World! Bash Script

Step 3: Open the file using any editor or visual studio. For using editor gedit, type

Step 4:Now Code for the intended script, i.e., Hello World!

Where, Line 1 represents #! (shebang) and specifies the bash shell location.

Line 2 represents the commented line.

Line 3 represents echo command to print the output.

Step 5:Execute the Script prefixing with ./.

Hello World! Bash Script

It will throw the Permission denied error. Because the file has only read and write permissions but not execute permission, you can see it below:

Hello World! Bash Script

So we add the execute permission to the file using chmodcommand with +x option as

and finally, execute the script.

Hello World! Bash Script




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA