Friday June 05, 2009 A colleague, lets call him Lewis, just popped over with the most bizarrely behaving shell script I have seen.
The problem was that the script would hang while the automounter timed out an attempt to NFS mount a file system on the customer's system.
I narrowed it down to something in a shell function that looked like this:
# Make a copy even if the destination already exists.
safe_copy()
{
typeset src="$1"
typeset dst="$2"
/* Nothing to copy */
if [ ! -f $src ] ; then
return
fi
if [ ! -h $src -a ! -h $dst -a ! -d $dst ] ; then
cp -p $src $dst || exit 1
fi
}
safe_copy was called with a file as the $1 and a file as $2.
I laughed when saw the problem. Funny how you can read something and miss such an obvious mistake!
Thankfully the script has quietly been fixed.
Except where otherwise noted, this site is
licensed under a Creative Commons License 2.0
This is a personal weblog, I do not speak for my employer.
| « December 2009 | ||||||
| Mon | Tue | Wed | Thu | Fri | Sat | Sun |
|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 | |||
| Today | ||||||
"Lewis" has been writing too much C I guess. :-)
Posted by Brett Monroe on June 05, 2009 at 07:45 PM BST #
I should point out that "Lewis" did not write the script. Perhaps he's been reading to much C or even D!
Posted by Chris Gerhard on June 06, 2009 at 11:37 AM BST #
As someone that does a lot of C but not much shell, any hints for the rest of us that haven't figured it out yet?
Posted by Sam Shinozaki on June 08, 2009 at 04:57 PM BST #
@Sam.
The problem is the comment.
/* does not delimit comments in the shell. Instead thanks to globbing it expands to every file in the root directory.
Posted by Chris Gerhard on June 08, 2009 at 06:08 PM BST #