Hello World Bash Shell Script

Here’s an example of a simple “Hello World” bash shell script:

#!/bin/bash

echo "Hello World"

To run the script, save it to a file with a .sh extension, make the file executable using the chmod command, and then run the file.

For example, to save the script to a file named hello.sh, you would run the following commands:

echo "#!/bin/bash

echo \"Hello World\"" > hello.sh
chmod +x hello.sh
./hello.sh

The first line of the script, #!/bin/bash, is called a shebang and tells the system which interpreter to use to run the script. In this case, it specifies that the script should be run by the bash shell.

The echo command is used to print the message “Hello World” to the terminal.

You can modify the script to perform other actions, such as processing command-line arguments, reading from and writing to files, and more.

Leave a Comment