Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-05
3
Medium Priority
?
546 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Expert Comment

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

Accepted Solution

by:
ravenpl earned 1000 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 1000 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 a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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…
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.:
Suggested Courses

721 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