The Bash shell can be interacted with by entering commands. Execute these commands by pressing the Return
key.
Outputting Hello, world!
:
echo "Hello, world!"
#> Outputs Hello, world! to the terminal
The command echo
is a built-in command used to print text into the terminal. A newline is appended by default.
Scripts allow the Bash shell to be run without any interaction. Anything that can be done in interactive mode can be done in non-interactive mode.
Follow these steps to transform the "hello, world!" output into a script:
Create a new file called hello-world.sh (you can name this file anything)
touch hello-world.sh
Make the script executable
chmod +x hello-world.sh
Write this code in hello-world.sh
#!/bin/bash
echo "Hello, world!"