Solved

special characters in linux - when is \t a tab or the time

Posted on 2011-03-05
3
528 Views
Last Modified: 2012-05-11
Hi

I'm not sure in linux how the difference between special characters work. When is \t a tab or the time. If i wanted to output a tab i could write

echo $'\t'

but if i wanted to set the shell prompt to show the time i would write

PS1='\t'

Why are they treated differently when both times i am creating a string?

thanks
0
Comment
Question by:andieje
3 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 35045780
which shell are you using?
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 250 total points
ID: 35045783
This is all about bash(shell) and how it handles the special characters.

You can
echo "\t" # displays \t
echo -e "\t" # displays tab
but PS1='\t' # uses time in prompt

So again, You always have to refer manual/documentation to find how an application handles special or escaped characters.
There's no such thing like \t always means tabulator.
0
 
LVL 22

Assisted Solution

by:blu
blu earned 250 total points
ID: 35046357
It depends on the context. There are no "universal" special characters. The C programming language defines a number of special characters that have become sort of defacto standards, primarily because much of the programs involved in the OS are written in either C or C++. But those special characters in C are defined only for character constants in programs and for certain output routines. It doesn't happen automatically in any string.

So, how special characters are handled on input depends on the program getting the input (also on the tty device driver if input is from a terminal). So, in this case the characters "\" and "t" are both actually stored in the string input. In the case of the bash shell, it is assigned to the PS1 variable as is, with no translation. Then, as part of the shell output routine, when it sees the "\t" in the prompt variable, instead of outputing the "\t", it outputs the current time.

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Xymon customize http timeout 2 84
Access_log 17 118
Debug VNC connection on CentOS7 server 22 83
route 2 traffic streams on single NIC 6 48
This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now