Bash and declare

kburtch-Zd07PnzKK1IAvxtiuMwx3w at public.gmane.org kburtch-Zd07PnzKK1IAvxtiuMwx3w at public.gmane.org
Wed Mar 29 15:03:40 UTC 2006



In addition to assigning attributes, declare is used with the nounset option.
 By declaring variables, Bash is able to check for spelling mistakes in
variables.  Otherwise Bash assumes that a badly spelled variable name is
really a new variable, something Perl doesn't do.

Ken B.

Christopher Browne <cbbrowne-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> said:

> On 3/29/06, Neil Watson <tlug-neil-8agRmHhQ+n2CxnSzwYWP7Q at public.gmane.org> wrote:
> > I bought Ken's book on Bash scripting.  In it he talks about using
> > 'declare' to initialize variables.  In Perl 'my' is used like declare
> > but, more specifically for variable scope.  What is the purpose of
> > declare?
> 
> It is used to indicate variable attributes.
> 
> declare -a arr
>   indicates that arr is an array
> 
> declare -i ival
>   indicates that ival stores integers, as opposed to strings/floats
> 
> declare -r rval
>   indicates that rval is now read-only
> 
> There are several other declaration options; see the man page :-).
> --
> http://www3.sympatico.ca/cbbrowne/linux.html
> "The true  measure of a  man is how he treats  someone who can  do him
> absolutely no good." -- Samuel Johnson, lexicographer (1709-1784)
> --
> The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
> TLUG requests: Linux topics, No HTML, wrap text below 80 columns
> How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
> 



-- 



--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list