View the Most Wanted LQ Wiki articles.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


Search this Thread
Old 10-27-2009, 07:22 AM   #1
Senior Member
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,393
Blog Entries: 1

Rep: Reputation: 64
what is the purpose of $"string" in bash ?

Hi !

What is the purpose of that '$' in front of an string, like in
echo $"usage: $0"
in bash scripts ?

You can see it all around in scripts at /etc/init.d but I was not able to figure out what is its purpose, neither found references to it in bash man page....

The only reference to it is indirect:
from bash man page:
        If  set,  $'string'  and  $"string"  quoting is performed within ${parameter} expansions enclosed in double quotes.
        This option is enabled by default.
Old 10-27-2009, 07:41 AM   #2
Senior Member
Registered: May 2008
Posts: 3,438

Rep: Reputation: 950Reputation: 950Reputation: 950Reputation: 950Reputation: 950Reputation: 950Reputation: 950Reputation: 950
I guess you didn't look hard enough. It's in the man-page fairly near the beginning, however, as the bash man-page is so big and ugly, I'll forgive you this once.

 Words  of the form $'string' are treated specially.  The word expands to string, with back-
       slash-escaped characters replaced as specified by the ANSI C  standard.   Backslash  escape
       sequences, if present, are decoded as follows:
              \a     alert (bell)
              \b     backspace
              \e     an escape character
              \f     form feed
              \n     new line
              \r     carriage return
              \t     horizontal tab
              \v     vertical tab
              \\     backslash
              \'     single quote
              \nnn   the eight-bit character whose value is the octal value nnn (one to three dig-
              \xHH   the eight-bit character whose value is the hexadecimal value HH (one  or  two
                     hex digits)
              \cx    a control-x character

       The expanded result is single-quoted, as if the dollar sign had not been present.

       A double-quoted string preceded by a dollar sign ($) will cause the string to be translated
       according to the current locale.  If the current locale is C or POSIX, the dollar  sign  is
       ignored.  If the string is translated and replaced, the replacement is double-quoted.
Old 10-27-2009, 10:29 AM   #3
Senior Member
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,393
Blog Entries: 1

Original Poster
Rep: Reputation: 64
Thank you very much, dear GazL, to being a so nice and understanding Guru !




Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl - Can't use string ("html") as an ARRAY ref while "strict refs" OldGaf Programming 9 08-11-2009 11:14 AM
Bash variable problem: cURL -b parameter (string form e.g. "name=value;n2=v2") sithemac Other *NIX 3 07-09-2008 06:15 PM
"Permission denied" and "recursive directory loop" when searching for string in files mack1e Linux - Newbie 5 06-12-2008 07:38 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
bash cripting function to "identify" any char in a string? minike Programming 8 02-01-2006 09:45 AM

All times are GMT -5. The time now is 08:31 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration