Re: Bash: pipe once more
On 2008-07-13T20:55:42+0200, Stefan Schmidt wrote:
> I want to change the working directory and if there is an error (e.g.
> the directory doesn't exist) I want that to be logged to a file and
> printed on stdout. With the above command that doesn't work since the
> working directory is the same as before execution of the command.
cd does not seem to do its thing when stdout is redirected to a pipe,
however it does work with a (temporary) file:
cd bad > cd.out 2>&1
Another way to go about this is to just do the cd, and write your own
error message if OLDPWD and PWD are the same.
Finally, you could check for the error conditions before doing the cd:
if [ -d $dir -a -x $dir ];
echo cannot cd into $dir