Solved

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

Posted on 2011-03-05
3
536 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 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
Upgraded from Debian 7 to 8.7 and got black screen 20 122
Samba 4, Users Permission, 5 112
regular expression help for sed command 5 62
Enable SPF on IMSVA 6 67
Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

739 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