Read input from the user with read, format output precisely with printf, and feed multi-line text into commands using here-documents and here-strings.
Why: read pauses the script and stores a typed line into a variable. -p shows a prompt on the same line; -r keeps backslashes literal (almost always what you want); -s hides typing, for passwords.
#!/usr/bin/env bash
read -r -p "Your name: " name
echo "Hi, $name"
read -r -s -p "Password: " pass # -s hides the typing
echo # move to a new line
echo "Got a ${#pass}-character password"Why: echo is fine for simple lines, but printf gives you real formatting and is portable. A format string uses placeholders: %s for a string, %d for an integer, %.2f for two decimal places. Note: unlike echo, printf does NOT add a trailing newline — you write \n yourself.
#!/usr/bin/env bash
printf "%s is %d years old\n" "Ada" 36
# Build aligned columns
printf "%-10s %5s\n" "Name" "Score"
printf "%-10s %5d\n" "Ada" 95
printf "%-10s %5d\n" "Grace" 100Why: a here-document (<<) feeds a block of lines into a command as its input — ideal for writing config files or printing help text without a dozen echo lines. Note: variables expand inside it; quote the marker (<<'EOF') to keep everything literal.
#!/usr/bin/env bash
name="Ada"
cat <<EOF > greeting.txt
Hello, $name.
This whole block is written to the file.
EOF
cat greeting.txtWhy: a here-string (<<<) feeds one short string to a command's standard input — handier than echo piped into the command. It pairs naturally with tools that read stdin, like grep, bc, or read.
#!/usr/bin/env bash
# Feed a string straight into grep's input
grep "lo" <<< "hello world" # -> hello world
# Split a line into variables
read -r first second <<< "one two"
echo "$first then $second" # -> one then two