Mask String

Mask a string showing only the last few characters, useful for credit cards or SSNs.

Code

Utilities
len=${#str}; maskLen=$((len - visibleChars)); printf "%0.s$maskChar" $(seq 1 $maskLen); echo "${str: -$visibleChars}"

Parameters

The string to mask.

Number of characters to show at the end.

Character to use for masking.

Server

More Bash Snippets