#!/bin/sh # sample-utf8.sh: UTF-8 test file for shell scripts. # Free sample from 99helpers.com/file-types/sh # Run: sh sample-utf8.sh (or bash sample-utf8.sh) # The shell doesn't decode the file: it passes the bytes through to the # terminal. Whether you see the text correctly depends on your terminal # and locale (the LANG and LC_ALL settings), not on the script. set -eu # 1. Which locale is this shell using? Step 3 depends on it. printf 'Locale: LANG=%s LC_ALL=%s\n' "${LANG:-unset}" "${LC_ALL:-unset}" # 2. Non-ASCII text, printed as is. for text in "Goedemorgen, café-eigenaar" "Grüß Gott, Straße" "Ça va, Zoë ?" \ "Καλημέρα" "Здравствуйте" "مرحبا" "שלום" "नमस्ते" \ "こんにちは" "你好" "안녕하세요" "€ £ ¥ ₹ ≤ ≥ ∞ ✓" "👋🌍🐚"; do # 3. ${#text} counts characters in bash, zsh and ksh with a UTF-8 locale, # but bytes in the C locale and in dash. wc -c always counts bytes. bytes=$(printf '%s' "$text" | wc -c | tr -d ' ') printf '%s (length %s, %s bytes)\n' "$text" "${#text}" "$bytes" done # 4. File names can be non-ASCII too: always quote them. file_name="résumé 2026.txt" printf 'A file name with an accent and a space: "%s"\n' "$file_name"