TechTalkz.com Logo Ask the Expert

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Linux & Opensource > Gentoo Linux

Notices

What does the colon minus operator do in a runscript shell?

Gentoo Linux


Reply
 
Thread Tools Display Modes
Old 02-12-2007, 03:41 PM   #1
Mark Hobley
Guest
 
Posts: n/a
What does the colon minus operator do in a runscript shell?

I am looking at a script written for the runscript shell. I have a line as
follows:

if [[ ${RC_INTERACTIVE:-yes} == "yes" ]] ; then

I would like to know what the :- (colon minus) operator that follows the
variable name does.

Mark.

--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/

  Reply With Quote
Old 02-12-2007, 05:47 PM   #2
Mark Hobley
Guest
 
Posts: n/a
Re: What does the colon minus operator do in a runscript shell?

In alt.os.linux.gentoo Mark Hobley <markhobley@hotpop.deletethisbit.com> wrote:

> I would like to know what the :- (colon minus) operator that follows the
> variable name does.


On further examination, I find:

declare -r svcdir="${svcdir:-/var/lib/init.d}"

So I guess that the colon minus operator returns the first argument if it is
not null, otherwise it returns the second argument.

Mark.

--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/

  Reply With Quote
Old 02-12-2007, 06:48 PM   #3
Michael Mauch
Guest
 
Posts: n/a
Re: What does the colon minus operator do in a runscript shell?

Mark Hobley wrote:

> I am looking at a script written for the runscript shell. I have a line as
> follows:
>
> if [[ ${RC_INTERACTIVE:-yes} == "yes" ]] ; then
>
> I would like to know what the :- (colon minus) operator that follows the
> variable name does.


Like in a normal (POSIX like) shell - "info bash" says:

${PARAMETER:-WORD}'
If PARAMETER is unset or null, the expansion of WORD is
substituted. Otherwise, the value of PARAMETER is substituted.

Regards...
Michael
  Reply With Quote
Old 02-12-2007, 10:00 PM   #4
Bit Twister
Guest
 
Posts: n/a
Re: What does the colon minus operator do in a runscript shell?

On Sun, 02 Dec 2007 10:08:28 GMT, Mark Hobley wrote:
>
> I would like to know what the :- (colon minus) operator that follows the
> variable name does.


You may want to consider printing out the Reference Cards section of
http://tldp.org/LDP/abs/html/index.html
  Reply With Quote
Old 02-12-2007, 11:01 PM   #5
Chris F.A. Johnson
Guest
 
Posts: n/a
Re: What does the colon minus operator do in a runscript shell?

On 2007-12-02, Michael Mauch wrote:
> Mark Hobley wrote:
>
>> I am looking at a script written for the runscript shell. I have a line as
>> follows:
>>
>> if [[ ${RC_INTERACTIVE:-yes} == "yes" ]] ; then
>>
>> I would like to know what the :- (colon minus) operator that follows the
>> variable name does.

>
> Like in a normal (POSIX like) shell


It is true for all 'Bourne-esque' shells.

> - "info bash" says:
>
> ${PARAMETER:-WORD}'
> If PARAMETER is unset or null, the expansion of WORD is
> substituted. Otherwise, the value of PARAMETER is substituted.



--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
  Reply With Quote
Old 03-12-2007, 01:10 AM   #6
Arthur Hagen
Guest
 
Posts: n/a
Re: What does the colon minus operator do in a runscript shell?

Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
> On 2007-12-02, Michael Mauch wrote:
>> Mark Hobley wrote:
>>
>>> I am looking at a script written for the runscript shell. I have a
>>> line as follows:
>>>
>>> if [[ ${RC_INTERACTIVE:-yes} == "yes" ]] ; then
>>>
>>> I would like to know what the :- (colon minus) operator that
>>> follows the variable name does.

>>
>> Like in a normal (POSIX like) shell

>
> It is true for all 'Bourne-esque' shells.


For ${FOO:-BAR}, yes, it should be available in all shells in the Bourne
family, as long as they follow the standards. Some other ${FOO:?YYY}
constructs, no -- bash provides its own extras. If your Bourne family shell
is less than a couple of decades old, it should support the standard
${XXX:?YYY} constructs.

Avoiding bashisms, i.e. bash functionality that locks the script to bash, is
considered a good thing. Using bashisms is, IMO, like writing web pages
that only render correctly with Internet Explorer. The use of [[ and ]] in
the above example is a bashism (or kshism, actually), and in this case
completely meaningless except to prevent the script from running under a
standard sh.

Regards,
--
*Art

  Reply With Quote
Old 05-12-2007, 01:43 AM   #7
Vilmos Soti
Guest
 
Posts: n/a
Re: What does the colon minus operator do in a runscript shell?

markhobley@hotpop.deletethisbit.com (Mark Hobley) writes:

> I am looking at a script written for the runscript shell. I have a line as
> follows:
>
> if [[ ${RC_INTERACTIVE:-yes} == "yes" ]] ; then
>
> I would like to know what the :- (colon minus) operator that follows the
> variable name does.


You might want to check out bash(1) and look for "Parameter Expansion".

Vilmos
  Reply With Quote
Old 05-12-2007, 02:21 AM   #8
Vilmos Soti
Guest
 
Posts: n/a
Re: What does the colon minus operator do in a runscript shell?

markhobley@hotpop.deletethisbit.com (Mark Hobley) writes:

> I am looking at a script written for the runscript shell. I have a line as
> follows:
>
> if [[ ${RC_INTERACTIVE:-yes} == "yes" ]] ; then
>
> I would like to know what the :- (colon minus) operator that follows the
> variable name does.


You might want to check out bash(1) and look for "Parameter Expansion".

Vilmos
  Reply With Quote
Old 14-12-2007, 08:33 PM   #9
Vilmos Soti
Guest
 
Posts: n/a
Re: What does the colon minus operator do in a runscript shell?

markhobley@hotpop.deletethisbit.com (Mark Hobley) writes:

> I am looking at a script written for the runscript shell. I have a line as
> follows:
>
> if [[ ${RC_INTERACTIVE:-yes} == "yes" ]] ; then
>
> I would like to know what the :- (colon minus) operator that follows the
> variable name does.


You might want to check out bash(1) and look for "Parameter Expansion".

Vilmos
  Reply With Quote
Old 14-12-2007, 08:33 PM   #10
Vilmos Soti
Guest
 
Posts: n/a
Re: What does the colon minus operator do in a runscript shell?

markhobley@hotpop.deletethisbit.com (Mark Hobley) writes:

> I am looking at a script written for the runscript shell. I have a line as
> follows:
>
> if [[ ${RC_INTERACTIVE:-yes} == "yes" ]] ; then
>
> I would like to know what the :- (colon minus) operator that follows the
> variable name does.


You might want to check out bash(1) and look for "Parameter Expansion".

Vilmos
  Reply With Quote
Reply

Thread Tools
Display Modes



< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 09:28 PM.


vBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2010, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional