Code · 1 file
Sample Bash File
Bash is the standard Unix shell for scripts and automation. The Bash sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.
Bash · 425 B
Sample Bash file
An idiomatic Bash example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.
CC0 · free for any use · Verified by an independent tool · Report a problem
#!/usr/bin/env bash
# Sample Bash script — samplefiles.com
set -euo pipefail
declare -A balances=([Ada]=12500 [Grace]=830.50 [Linus]=10000)
total=0
for name in Ada Grace Linus; do
balance=${balances[$name]}
vip=""
if (( $(echo "$balance >= 10000" | bc -l) )); then vip="VIP"; fi
printf "%-6s %10.2f %s\n" "$name" "$balance" "$vip"
total=$(echo "$total + $balance" | bc -l)
done
printf "Total: %.2f\n" "$total"File details
Download from the command line
curl -L -o sample.sh https://files.samplefiles.com/code/sh/sample.shwget https://files.samplefiles.com/code/sh/sample.shhttps://files.samplefiles.com/code/sh/sample.shprintf '%s %s\n' 2b3b104821661c3d23d65b48a1fd9460c41c2e00b457727928707334bdfc6b32 sample.sh | shasum -a 256 -cOr check the download in your browser with the checksum calculator.