Re: bash-2.05.0(1) bug or new feature
On Tue, Aug 28, 2001 at 08:21:52PM -0700, Dan Wilder wrote:
[snip]
> However, when cd is used in a script, this can have other consequences.
> For example, a script intended to process all the leafnode names of some
> files:
>
> #!/bin/sh
>
> (cd test; ls) | while read file
> do
> echo -- $file --
> done
>
> if run on a directory that contained files named 1, 2, and 3, once
> produced
>
> -- 1 --
> -- 2 --
> -- 3 --
>
> but now produces
>
> -- /home/dan/test --
> -- 1 --
> -- 2 --
> -- 3 --
With an alias for "cd" as "pushd"...
-------------------------------
#!/bin/sh
alias cd=pushd
(cd test; ls) | while read file
do
echo -- $file --
done
-------------------------------
$ ./changedir
-- /tmp/test /tmp --
-- 1 --
Not exactly the same, but close... Probably better not to have your "cd"
grouped with the "ls" anyway. Still, can't reproduce your output...
...
PREVIOUS=$(pwd)
cd test
for i in $(ls -1); do
echo "-- $i --"
done
cd "$PREVIOUS"
...
Or you could use pushd/popd (but they're bashism's, as is "read"
apparently...).
--
Eric G. Miller <egm2@jps.net>
Reply to: