/pt-br/jnl/2025-08-26t14-45-37-len-no-bash.md


len no Bash

· #public #bash #script

len no Bash

Script Bash para retornar o tamanho de uma string, muito útil para uso rápido no terminal.

#!/bin/bash
# Description: Get the length of a string
# Usage: len <string>
# Example: len "hello world"
# Output: 11

set -euo pipefail

[ "$#" -ne 1 ] && { echo "Usage: len <string>" >&2; exit 1; }
printf '%d\n' "${#1}"

crg.eti.br · © 2026 Cesar Gimenes · CC BY 4.0 · github