Learning Bash Part 1: Hello World

posted 2 years ago

Interactive Mode

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.

Non-Interactive Mode

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:

  1. Create a new file called hello-world.sh (you can name this file anything)

    touch hello-world.sh
    
  2. Make the script executable

    chmod +x hello-world.sh
    
  3. Write this code in hello-world.sh

    #!/bin/bash
    echo "Hello, world!"