Hello, World

The smallest Bash script, echo and printf, and why to quote variables.

Runs in Zerethon IDE · Bash 5.2 Official Bash documentation ↗

A Bash script is a list of commands run from top to bottom. echo prints its arguments and a newline; printf prints exactly the format you give it.

main.sh
#!/usr/bin/env bash

echo "Hello, World!"
echo "Sum: $((2 + 3))"
printf '%s-%s!\n' a b
name="Ada"
echo "Hi, $name"

Output

Hello, World!
Sum: 5
a-b!
Hi, Ada
  • Double quotes expand variables ("$name"); single quotes keep every character as written ('$name').
  • Quote variables when you use them: "$file" keeps a name with spaces as one argument.
  • The first line #!/usr/bin/env bash (the shebang) tells a system which interpreter to use. Run uses Bash either way.