Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 07-13-2011, 06:30 PM   #1
Registered: Mar 2010
Posts: 58

Rep: Reputation: 5
Post Odd bash construction...

Context: I'm trying to spruce up the file that comes with a jboss installation, so that it provides the same [ OK ] / [ FAILED ] flags that most of the other /etc/init.d/ scripts have. The file is jboss's auto start/stop for RH.

(I don't have to, but it's a good way to stretch my scripting knowledge...)

I'm using /etc/init.d/sshd as my model, and I've encountered this echo line:

echo -n $"Starting $prog: "
I get the -n. I get the $prog variable for expansion. I even get providing the space at the end of the string.

What in the world is that dollar sign supposed to be doing? Turning the whole string into a variable?!

Old 07-13-2011, 06:42 PM   #2
LQ Newbie
Registered: Jul 2011
Posts: 8

Rep: Reputation: Disabled
This is done for localization. It allows the string to be translated to a different language depending on your locale.

For example, after a bit of setup, I can print the output of this code in another language:


echo $"Hello!"
echo $"How are you?"
Here in the US English locale, I get one output:
$ LANG=en_US.utf8
$ ./
How are you?
And in the France French locale, I get another:

$ LANG=fr_FR.utf8
$ ./
Comment allez-vous?
For more details on how to do that, check out this reference:

Last edited by lamouche; 07-13-2011 at 06:59 PM. Reason: Added an example
1 members found this post helpful.
Old 07-13-2011, 11:09 PM   #3
Registered: Mar 2010
Posts: 58

Original Poster
Rep: Reputation: 5
Slick! Thanks for the hint.
Old 07-14-2011, 12:11 AM   #4
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,826

Rep: Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973
Notice that there's also a single-quoted version, $'string', that has a different, more generally useful purpose. Any ansi-c style backslash escapes will be expanded into their literal equivalents, and the result will be a hard-quoted string. It's generally equivalent to the "-e" option in echo.

$ echo $'foo\tbar\nbaz\tbum'
foo     bar
baz     bum
1 members found this post helpful.


bash scripting

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
Bash script for renaming files (all odd) snaggletooth1134 Programming 10 05-01-2012 12:26 AM
Parenthesis and other odd characters passed to bash function jakeo25 Programming 2 04-03-2008 10:27 AM
spaces and odd characters in directory name in bash? babag Programming 1 04-02-2008 03:28 PM
Odd Chars w/ make/C++ compile error on Fedora w/bash shell zemux Linux - General 2 01-22-2006 01:48 AM
odd "pppd call" behaviour in bash on fc3 kijoma Linux - Networking 1 08-19-2005 05:57 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:44 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration