Solved

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

Posted on 2011-03-05
3
533 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

685 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