f



what is . command and : command?

hello,
  I am confused with . command and : command usage. can anybody help me
to understand it with simple examples?
Thanks in advance.
regards,
rahul

0
rahul8143
9/6/2005 5:15:14 PM
comp.os.linux.development.apps 5216 articles. 1 followers. Post Follow

10 Replies
1940 Views

Similar Articles

[PageSpeed] 29

On Tue, 06 Sep 2005 13:15:14 -0400, <rahul8143@gmail.com> wrote:

> hello,
>   I am confused with . command and : command usage. can anybody help me
> to understand it with simple examples?
> Thanks in advance.
> regards,
> rahul
>
>


.. means execute the following script in "this" shell as if it were
a part of this shell's input or script that is currently running.
One use is to read in config variables.

: is a synonym for "true". It does nothing but return an "ok" status.
One use is for making infinite "while" loops.
0
Joe
9/6/2005 5:53:00 PM
On 6 Sep 2005 10:15:14 -0700, rahul8143@gmail.com 
  <rahul8143@gmail.com> wrote:
> hello,
>   I am confused with . command and : command usage. can anybody help me
> to understand it with simple examples?

man sh
 : is a null command.  It may be used in a loop
  while : ; do echo "yada yada"; done
  until ping -c 1 host; do : ; done
or it can be used to set variables
  : ${VAR:=default}
"." is the "source" command.  It reads and executes a script without 
spawning a subshell, so the script can modify variables and define 
functions and aliases which persist after the script ends.


-- 
Atlanta makes it against the law to tie a giraffe to a telephone pole
or street lamp.
0
Bill
9/6/2005 5:58:06 PM
Joe Beanfish writes:
> : is a synonym for "true". It does nothing but return an "ok" status.

Not quite.  It also expands arguments and performs redirections.
-- 
John Hasler 
john@dhh.gt.org
Dancing Horse Hill
Elmwood, WI USA
0
John
9/6/2005 6:25:40 PM
John Hasler wrote:
> 
> Joe Beanfish writes:
> > : is a synonym for "true". It does nothing but return an "ok" status.
> 
> Not quite.  It also expands arguments and performs redirections.

You are mistaken. None of the commands does this. The shell
does it before even finding out what the command is. Can you
give any example where : and true behaves differently?

-- 
Kasper Dupont
Note to self: Don't try to allocate
256000 pages with GFP_KERNEL on x86.
0
Kasper
9/6/2005 7:49:44 PM
I wrote:
> Not quite.  It also expands arguments and performs redirections.

Kasper Dupont writes:
> You are mistaken. None of the commands does this. The shell
> does it before even finding out what the command is.

From the Bash info doc:

Bourne Shell Builtins
=====================

   The following shell builtin commands are inherited from the Bourne
Shell.  These commands are implemented as specified by the POSIX 1003.2
standard.

`:    (a colon)'
          : [ARGUMENTS]
     Do nothing beyond expanding ARGUMENTS and performing redirections.
     The return status is zero.

-- 
John Hasler 
john@dhh.gt.org
Dancing Horse Hill
Elmwood, WI USA
0
John
9/6/2005 9:52:12 PM
John Hasler wrote:
> 
> I wrote:
> > Not quite.  It also expands arguments and performs redirections.
> 
> Kasper Dupont writes:
> > You are mistaken. None of the commands does this. The shell
> > does it before even finding out what the command is.
> 
> From the Bash info doc:
> 
> Bourne Shell Builtins
> =====================
> 
>    The following shell builtin commands are inherited from the Bourne
> Shell.  These commands are implemented as specified by the POSIX 1003.2
> standard.
> 
> `:    (a colon)'
>           : [ARGUMENTS]
>      Do nothing beyond expanding ARGUMENTS and performing redirections.
>      The return status is zero.

The documentation doesn't explain every litle detail,
and so what? Take a look on the implementation, it is
in fact quite simple:

/* Return a successful result. */
int
colon_builtin (ignore)
     char *ignore;
{
  return (0);
}

This is taken directly from the bash-3.0 source
(bash-3.0/builtins/colon.def). And that is the
implementation used for : and true.

-- 
Kasper Dupont
Note to self: Don't try to allocate
256000 pages with GFP_KERNEL on x86.
0
Kasper
9/7/2005 9:39:23 AM
On a sunny day (Wed, 07 Sep 2005 11:39:23 +0200) it happened Kasper Dupont
<kasperd@daimi.au.dk> wrote in <431EB54B.9E72B6B0@daimi.au.dk>:
>/* Return a successful result. */
>int
>colon_builtin (ignore)
>     char *ignore;
>{
>  return (0);
>}
>
>This is taken directly from the bash-3.0 source
>(bash-3.0/builtins/colon.def). And that is the
>implementation used for : and true.
Funny that in bash-3.0 they do not write 
return 0;
return is not a function.
0
Jan
9/7/2005 5:56:48 PM
Jan Panteltje <pNaonStpealmtje@yahoo.com> writes:

> On a sunny day (Wed, 07 Sep 2005 11:39:23 +0200) it happened Kasper Dupont
> <kasperd@daimi.au.dk> wrote in <431EB54B.9E72B6B0@daimi.au.dk>:
>>/* Return a successful result. */
>>int
>>colon_builtin (ignore)
>>     char *ignore;
>>{
>>  return (0);
>>}
>>
>>This is taken directly from the bash-3.0 source
>>(bash-3.0/builtins/colon.def). And that is the
>>implementation used for : and true.
> Funny that in bash-3.0 they do not write 
> return 0;
> return is not a function.

It's probably some silly coding style rule.  All GNU software uses a
lot of very ugly rules.

-- 
M�ns Rullg�rd
mru@inprovide.com
0
iso
9/7/2005 6:19:16 PM
> Jan Panteltje <pNaonStpealmtje@yahoo.com> writes:
> 
> > On a sunny day (Wed, 07 Sep 2005 11:39:23 +0200) it happened Kasper Dupont
> > <kasperd@daimi.au.dk> wrote in <431EB54B.9E72B6B0@daimi.au.dk>:
> >>/* Return a successful result. */
> >>int
> >>colon_builtin (ignore)
> >>     char *ignore;
> >>{
> >>  return (0);
> >>}
> >>
> >>This is taken directly from the bash-3.0 source
> >>(bash-3.0/builtins/colon.def). And that is the
> >>implementation used for : and true.
> > Funny that in bash-3.0 they do not write 
> > return 0;
> > return is not a function.

I see an astonishing number of programs that do that.  For that
matter, when I started programming I did that; it's taken a conscious
effort to break myself of it (and I still catch myself doing it).
-- 
Joseph J. Pfeiffer, Jr., Ph.D.       Phone -- (505) 646-1605
Department of Computer Science       FAX   -- (505) 646-1002
New Mexico State University          http://www.cs.nmsu.edu/~pfeiffer
                                     skype:  jjpfeifferjr
0
Joe
9/7/2005 8:28:50 PM
M�ns Rullg�rd wrote:
> Jan Panteltje <pNaonStpealmtje@yahoo.com> writes:
> 
> 
>>On a sunny day (Wed, 07 Sep 2005 11:39:23 +0200) it happened Kasper Dupont
>><kasperd@daimi.au.dk> wrote in <431EB54B.9E72B6B0@daimi.au.dk>:
>>
>>>/* Return a successful result. */
>>>int
>>>colon_builtin (ignore)
>>>    char *ignore;
>>>{
>>> return (0);
>>>}
>>>
>>>This is taken directly from the bash-3.0 source
>>>(bash-3.0/builtins/colon.def). And that is the
>>>implementation used for : and true.
>>
>>Funny that in bash-3.0 they do not write 
>>return 0;
>>return is not a function.
> 
> 
> It's probably some silly coding style rule.  All GNU software uses a
> lot of very ugly rules.
> 

It's the old K&R style. The parentheses do nothing
here, as a parnethesized expression will return the
value from the inside of the parentheses. It's no harm,
but unnecessary.

-- 

Tauno Voipio
tauno voipio (at) iki fi

0
Tauno
9/7/2005 8:36:28 PM
Reply: