![]() |
![]() |
|
|||||||
| Register | Forum Rules | Getting Started! - Guide | Blog | Videos | Gallery | Members List | Social Groups | Mark Forums Read |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
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/ |
|
|
|
#2 |
|
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/ |
|
|
|
#3 |
|
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 |
|
|
|
#4 |
|
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 |
|
|
|
#5 |
|
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 |
|
|
|
#6 |
|
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 |
|
|
|
#7 |
|
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 |
|
|
|
#8 |
|
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 |
|
|
|
#9 |
|
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 |
|
|
|
#10 |
|
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 |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
< Home - Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |