How do I echo one or more tab characters using a bash script? When I run this code
res=' 'x # res = "\t\tx" echo '['$res']' # expect [\t\tx]
I get this
res=[ x] # that is [<space>x]
Use the verbatim keystroke, ^V ( CTRL+V , C-v , whatever). When you type ^V into the terminal (or in most Unix editors), the following character is taken verbatim. You can use this to type a literal tab character inside a string you are echoing.
Ctrl-v, Ctrl-i will also work (I found this answer here). Also, I think a Ctrl-q, Ctrl-v, Tab will work. Thanks L2G!
$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.
The echo command is used to display a line of text that is passed in as an argument. This is a bash command that is mostly used in shell scripts to output status to the screen or to a file.
echo -e ' \t '
will echo 'space tab space newline' (-e
means 'enable interpretation of backslash escapes'):
$ echo -e ' \t ' | hexdump -C 00000000 20 09 20 0a | . .|
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With