Execute Bash commands, use builtins, perform variable expansion and globbing. Use when running shell commands, checking command availability, parsing command output, or building command strings with expansion.
Execute commands in the Bourne Again SHell — the default command interpreter on most Linux systems.
&), or subshell ($(...))"$variables"$?) or use &&/|| for conditional chainingoutput=$(command arg1 arg2 2>&1)
exit_code=$?
if command -v jq &>/dev/null; then
echo "jq is available"
else
echo "jq is not installed" >&2
fi
port="${PORT:-8080}" # Default if unset
dir="${WORKDIR:?WORKDIR required}" # Error if unset
name="${FULL_NAME%% *}" # Remove after first space
ext="${filename##*.}" # Extract extension
# Chain — stop on failure
mkdir -p build && cd build && cmake ..
# Test file existence
[[ -f config.json ]] && echo "Config found"
# Pattern match
[[ "$url" =~ ^https?:// ]] && echo "Valid URL"
# Standard globs
ls *.ts # All .ts files
ls src/**/*.test.ts # Recursive (needs shopt -s globstar)
# Brace expansion
mkdir -p src/{components,utils,hooks}
cp file.{js,bak} # Copy file.js to file.bak
"$var", "$@", "$(cmd)"[[ ]] is Bash-specific; [ ] is POSIX but splits words and expands globs`cmd` are legacy — use $(cmd) which nests cleanlyset -e makes scripts exit on any unhandled failure — sometimes too aggressive for interactive use*.xyz returns the literal string if no match; use shopt -s nullglob to get empty results$(cmd) can cause bugs with filenames containing spaceseval is dangerous — avoid unless absolutely necessary; prefer arrays for dynamic commands