LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 07-13-2011, 06:30 PM   #1
dafydd2277
Member
 
Registered: Mar 2010
Posts: 58

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


Context: I'm trying to spruce up the jboss_init_redhat.sh 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:

Code:
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?!

Thanks!
dafydd
 
Old 07-13-2011, 06:42 PM   #2
lamouche
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:
Code:
#!/bin/bash

TEXTDOMAINDIR=/usr/local/share/locale
TEXTDOMAIN=hi

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

Code:
$ LANG=fr_FR.utf8
$ ./hi_locales.sh
Bonjour!
Comment allez-vous?
For more details on how to do that, check out this reference: http://www.cyberciti.biz/faq/bash-lo...-echo-command/

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
dafydd2277
Member
 
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,823

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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.

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


Reply

Tags
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


All times are GMT -5. The time now is 12:23 AM.

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