Hello World
Bash · Reference cheat sheet
Hello World
Bash · Reference cheat sheet
📋 Overview
Bash Hello World prints a line to the terminal with echo (or printf). It confirms you can run commands and, optionally, execute a script file.
🔧 Core concepts
| Piece | Role |
|---|---|
echo | Print arguments followed by a newline |
printf | Formatted print (more predictable) |
| Shebang | Selects the interpreter for scripts |
./file | Run a file in the current directory |
bash file.sh | Run a script without the executable bit |
Prefer printf when you care about exact formatting; echo is fine for learning.
💡 Examples
Interactive:
echo "Hello, World!"
printf '%s\n' "Hello, World!"Script file:
#!/usr/bin/env bash
echo "Hello, World!"bash hello.shWith a variable:
#!/usr/bin/env bash
name="Ada"
echo "Hello, ${name}!"Show command success:
echo "Hello, World!"
echo "exit status was $?"⚠️ Pitfalls
echo $namewithout quotes breaks on spaces — prefer"$name".- Some
echoflags differ across systems;printfis more portable. - Running
sh hello.shmay not be Bash ifshis dash. - CRLF line endings from Windows editors can break shebang scripts.