This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[Fwd: Re: Cygwin/Bash: Some builtins done work in scripts]


Another option here that I was asked to forward to the list:

-------- Original Message --------
Subject: Re: Cygwin/Bash: Some builtins done work in scripts
Date: Thu, 11 Oct 2001 08:58:08 -0700
From: RCUNNINGHAM@redlake.com
To: jmerz42@earthlink.net

Unfortunately, my email server is on ORDB, and I can't post to the list.
If you think it is worth it, would you please forward this to the list for
me?

-----

There is another trick to use that may help:  Within a bash script, any
bash builtin may be preceded by the word "builtin" to force the command
lookup mechanism to check only the builtin list (this has the benefit of
bypassing the initial check of the function list, and thus allows bash
builtins to be used within shell functions, especially functions that have
the same name as the builtin it needs to call).  This mechanism also
prevents checking for an executable of the same name in the path.  The
command name following the word "builtin" must contain no slashes.

Now, if you create an executable called "builtin" and place it in your
path, it could then be used as a redirector to mimic the behavior of the
bash builtins when scripts are run under non-bash shells.  I haven't done
this, but it is certainly possible.  I had once implemented pushd, popd and
dirs as stand-alone executables that used a "DIRSTACK" environment
variable, but that was 20 years ago and I no longer have the sources.  But
they shouldn't be too hard to recreate.

Of course, shebang bash is the "right" way to go.


-BobC

Rainer Klute wrote:

 > Hi,
 >
 > I hope you are the right one to report a bug to I just encountered in
Cygwin's
 > bash: The builtins pushd, popd and dirs don't work when I use them in a
 > script file. The error message is e.g. "pushd: not found". Other
builtins,
 > like "cd" work in scripts. At the tty the faulty builtins works fine. Its
 > just in scripts. (Needless to say that under Unix (Linux) the buildins
work
 > in scripts.)
 >
 > I am using Cygwin 1.3.2-1 and bash 2.05-6. The version number I extracted
 > from the setup.log.


Make sure that you have #!/usr/bin/bash on the first line of your script.
I
think that if you don't specifically use bash, scripts will be executed
using
sh, which does not have pushd, popd, or dirs as builtins.  The following
script works fine for me, but if I change the 'bash' to 'sh' or remove the
line all together, I get the "not found" errors.

#!/usr/bin/bash

pwd
pushd .
dirs
cd winnt
pwd
dirs
popd


--


-------------------------------------
   If you had a million Shakespeares,
   could they write like a monkey?





-- 


-------------------------------------
  If you had a million Shakespeares,
  could they write like a monkey?


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]