Bash Syntax References

Bash scripting syntax quick reference: variables, tests, loops, functions and redirection, from the GNU Bash manual. Every item below is clearly marked as a shortcut, command, or syntax reference.

Most Useful Bash Syntax References

BashSyntax

Print Text

Code example
echo "Hello"

Prints text to the terminal.

Learn More
BashSyntax

Set a Variable

Code example
name="Ada"

Assigns a value (no spaces around =).

Learn More
BashSyntax

If Statement

Code example
if [[ -f file.txt ]]; then echo "exists" fi

Runs code when a test is true.

Learn More
BashSyntax

Shebang Line

Code example
#!/bin/bash

Makes a script run with Bash.

Learn More
BashSyntax

Use a Variable

Code example
echo "Hi $name"

Expands a variable's value.

Learn More
BashSyntax

For Loop over a List

Code example
for f in *.txt; do echo "$f" done

Loops over words or files.

Learn More
BashSyntax

Redirect Output to a File

Code example
command > out.txt command >> out.txt

Writes (>) or appends (>>) output to a file.

Learn More
BashSyntax

Pipe Commands

Code example
cat log.txt | grep error

Sends one command's output into another.

Learn More

More Bash Syntax References

Frequently Asked Questions

What does this Bash syntax reference cover?

It covers 36 common Bash patterns and examples, including Print Text, Set a Variable, If Statement, Shebang Line, Use a Variable.

Can I copy the Bash examples?

Yes. Each reference page includes a copyable code example.

What affects these Bash examples?

Check the linked documentation for language or runtime version requirements. Libraries, file paths, terminal quoting and environment settings can differ across systems; no blanket platform compatibility is implied.