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

sample.sh — first linesShell
#!/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

Size
425 B (425 bytes)
MIME type
application/x-sh
SHA-256
2b3b104821661c3d23d65b48a1fd9460c41c2e00b457727928707334bdfc6b32
MD5
847b042eb0893f09266fa8c0e9f5ef19

Download from the command line

curl -L -o sample.sh https://files.samplefiles.com/code/sh/sample.sh

Or check the download in your browser with the checksum calculator.