Mailinglist Archive: opensuse (2772 mails)
| < Previous | Next > |
Re: [opensuse] Another Bash scripting question
- From: Randall R Schulz <rschulz@xxxxxxxxx>
- Date: Mon, 19 May 2008 06:53:34 -0700
- Message-id: <200805190653.34617.rschulz@xxxxxxxxx>
On Monday 19 May 2008 02:47, David Bolt wrote:
If you want to make it really bulletproof and consider the kind of
aliasing that could come about through hard or symbolic links, you
could test for sameness by using the "stat" command and testing for
equality of both the device and inode numbers:
[ "$(stat -c '%D-%i' "$file")" == "$(stat -c '%D-%i' "$OUTFILE")" ] \
&& continue
Well, that's your prerogative, but it's not too hard to write scripts
with the necessary precautions.
Randall Schulz
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
...
Well, one bug I spotted was that there's at least one major problem
that goes unchecked. What happens if ${INFILE} == ${OUTFILE}? I'd
hazard a guess that sox would open ${file}[0] to read, then open
${OUTFILE} for writing, then see ${file} has just become a 0-length
file and terminate. That sort of problem is easily fixed with a
simple addition of:
# skip if input and output files are the same
#
[ "${file}" == "${OUTFILE}" ] && continue
to the loop.
If you want to make it really bulletproof and consider the kind of
aliasing that could come about through hard or symbolic links, you
could test for sameness by using the "stat" command and testing for
equality of both the device and inode numbers:
[ "$(stat -c '%D-%i' "$file")" == "$(stat -c '%D-%i' "$OUTFILE")" ] \
&& continue
...
The only time this is going to break is when a filename contains an
ASCII character 0x0a, or line feed. However, anyone stupid enough to
include one of those in a filename should expect breakage and can
figure out how to fix the script to handle those files themselves.
Well, that's your prerogative, but it's not too hard to write scripts
with the necessary precautions.
Regards,
David Bolt
Randall Schulz
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
| < Previous | Next > |