[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

CDPATH and shell scripts



Hi,

it seems to me that the current CDPATH behaviour is verry strange and
extremly dangerous for shell scripts.

For those that have never heart of CDPATH it does 2 things:

1) a relative "cd" command with search the CDPATH for the given
   directory. If unset then '.' is used.

2) it outputs the path it used to stdout.

Now say you have the following script:

#! /bin/sh

cd /tmp
mkdir src
cd src
: do something
FOO=$(cd bar && cat blub)
rm -rf *
cd ..
rmdir src

Calling that with CDPATH=~ exported will 'rm -rf ~/src'. That will be
fun. It also suddenly outputs to stdout totally changing the value of
FOO.


So what is the right course of action here?

1) unset CDPATH in every single shell script there is?
2) never use relartive paths for cd in scripts?
3) shoot the user for doing something dumb?
4) disable CDPATH in /bin/sh (or is that POSIX?) or non-interactive
   scripts (would break automake I think)

MfG
        Goswin


Reply to: