B20: declare built-in doesn't work in scripts, work around

Earnie Boyd earnie_boyd@yahoo.com
Fri Dec 31 13:28:00 GMT 1999


--- Chris Marshall <chrism@NORCOM.NET> wrote:
> I am using beta 20.0 under NT 4.0.
> 
> Running the following script:
> 
> 	declare -i count

A bashism.  Isn't supported by sh.

> 	count=0
> 	count=count+1
> 	count=count+1
> 	echo count is ${count}
> 
> should produce the output:
> 
> 	count is 2
> 
> but instead produces the output:
> 
> 	declare: not found
> 	count is count+1
> 
> If the above script is in the file "do_it" and I run it from the bash
> command line by typing "./doit" I get the wrong output.
> 

If your here document is #!/bin/sh then you're not executing the script under
bash but under sh and the two aren't the same.  Again, declare is a bashism. 
If your here document is #!/bin/bash then the script will work correctly.

> If I run it with "source ./doit" it works correctly.
> 
> A better work-around to use in general is "( source ./doit )" so that when
> the "exit" command appears in the script you are executing, the bash command
> shell doesn't disappear.
> 
> Chris Marshall
> 
> p.s.  Here is the output of cygcheck -s -v -r for my machine:
> Cygnus Win95/NT Configuration Diagnostics
> Current System Time: Thu Dec 30 14:15:43 1999
> 
-8<-

I notice that you have no HOME variable.  Also, you're using the stock b20.1
Cygwin1.dll.  Please read my webpage.



=====
Earnie Boyd < mailto:earnie_boyd@yahoo.com >
Cygwin Newbies, please visit
< http://www.freeyellow.com/members5/gw32/index.html >
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://messenger.yahoo.com

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com



More information about the Cygwin mailing list