in reply to check if chdir() has work

The classic programming trope for testing chdir is:

chdir $my_dir or die("Cannot cd into directory $my_dir.\n");
It's a moderately important trope as well. At a former employer, they had shell code that went something like:

#!/bin/ksh Important_Directory=/foo/bar cd Important_Directory rm -rf * # # more stuff here #
See, when chdir fails, and you're root, you end up in the root directory. And the server on which this script was run, well the Important Directory was moved for some reason. And so the script cd's to "/" and the next command started running..

Replies are listed 'Best First'.
Re^2: check if chdir() has work
by runrig (Abbot) on Mar 14, 2008 at 17:17 UTC
    You will want to include $! somewhere in your error message, so you'll know why chdir has failed.