[Gllug] Why does this script not work?

tet at accucard.com tet at accucard.com
Sun Jul 15 10:10:06 UTC 2001


>I want a script that will change my current working directory to the 
>path above, the same as 'cd ..'.

Can't be done. Each process under Unix has its own concept of a current
directory. When you start a script, it creates a new process, and yours
will alter the current directory of that process, as you expect. The
script will then exit, but the current directory of its parent process
(i.e., the one from which you started the script) won't have changed.

The only way to do this is to run something in the context of the current
process, rather than as a separate one. In Bourne related shells, you can
use a shell function:

	cdfunc()
	{
		pwd
		cd ..
		pwd
	}

If you put this in your ~/.bashrc, for example, then "cdfunc" will do
what you want.

In csh, you can use a shell alias to achieve a similar effect.

Tet

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list