brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: $'\t' puts a real tab or newline into a shell string

Shell
~/tips/tip-shell-ansi-c-quoting-tab

IFS=$'\t' read -r name size <<< $'backup.tar\t1048576'

Writes tab and newline characters in a shell string with ANSI-C quoting.

Writing a backslash and a t inside plain single quotes gives a backslash and a t, so I use ANSI-C quoting.

IFS=$'\t' read -r name size <<< $'backup.tar\t1048576'
echo "$name has $size bytes"

Inside $'...' the shell turns escapes such as \t, \n and \x41 into real characters. Plain single quotes keep the backslash as typed, so IFS='\t' would split on a backslash and the letter t. Setting IFS in front of read affects only that command. ANSI-C quoting is supported by bash, zsh and ksh but not by POSIX sh, where you can use printf to create the character.

Further reading: Bash manual: ANSI-C Quoting

More Shell tips zmv -n '(*).log' '$1.txt' zoxide query -ls project f=$(mktemp --suffix=.json) shopt globskipdots echo $EPOCHSECONDS All Shell tips (78) All topics

Link