Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How would i echo a tab? ive tried /t like in c++ and /TAB which i got from google somewhere. Neither worked unless im putting them in the wrong side of quotations.
this is what im trying to do:
touch $Namepath/$1 #create file
echo "\$TTL 3h" >> $Namepath/$1
echo "$1 IN SOA ns1.$1 coldbeaver.$1." >> $Namepath/$1
now i want to echo with a tab so ive tried:
echo "\t blah blah" >> $Namepath
and ive tried
echo /t "blah blah" >> $Namepath
but neither worked. Any help is appreciated
Click here to see the post LQ members have rated as the most helpful post in this thread.
'echo -e' works because of built-in functionality of echo. In general, if you want to insert tab in bash, you can force a literal tab by typing Ctrl-V TAB or the equivalent Ctrl-V Ctrl-I; this also works for other special characters.
This works, but is unreliable in scripts and copy-and-paste snippets, so I recommend the ultimate way using bash's escape character variables. They are described (poorly) in the manual; to get the tab you'd do $'\t'. Caution: unfortunately this doesn't work within the double-quoted strings, so if you need tabs and spaces, you have to do things like "a b"$'\t'
Last edited by przemek.klosowski; 06-16-2011 at 09:41 AM.
To summarize the solutions given above, and to add one:
Code:
$ echo '[ ]' # enter a literal tab with <ctrl+v><tab>
[ ]
$ echo -e '[\t]'
[ ]
$ echo $'[\t]'
[ ]
$ printf '[%b]\n' '\t' # %b interprets backslashes in the same way as -e and $''
[ ]
Note also that these are all true for bash, but may be different for other shells. I believe that echo ksh, for example, automatically interprets backslashes without the use of any options.
Finally, since <tab> is ascii 011 (octal) and x09 (hex), you can also use \011 or \x09 instead of \t. And from bash 4.2+ you can also use the unicode code point \u09.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.