Mailinglist Archive: opensuse (2772 mails)

< Previous Next >
[opensuse] Another Bash scripting question
  • From: Rodney Baker <rodney.baker@xxxxxxxxxxxx>
  • Date: Sat, 17 May 2008 23:03:24 +0930
  • Message-id: <200805172303.33324.rodney.baker@xxxxxxxxxxxx>
Hi all.

I have a few directories containing wav files that have been ripped from CDs
and I'm trying to write a script to invoke sox to convert them to mp3 format.

The filenames have whitespaces and hyphens in them e.g. 'artist - 01 - title
with many words.wav'. I tried the following script but I'm obviously doing
something wrong...


for file in `find * -print0 | xargs --null`

do {
echo "$OUTFILE"

# if [ ! -e "$file" ]
# then
# echo "$file does not exist."; echo

# else

# sox "$file" "$OUTFILE"

# fi

# if [ $? -eq 0 ]
# then
# rm -f "$file"
# fi

exit 0

In its current form each word of each filename is treated separately i.e.
xargs --null appears to have no effect at all - it is interpreting whitespace
as a delimiter.

If I modify the first line as follows:

for file in "`find * -print0 | xargs --null`"


for file in "$(find * -print0 | xargs --null)"

then I get the entire directory listing (i.e. all the filenames) concatenated
into a single parameter with only the last file extension replaced.

What have I missed here? I'm assuming it is something to do with the pipe or
redirection via xargs that is not working as expected.

BTW, I also tried this:

for file in $(xargs --null -- < `find * -print0`)

but then I get an "ambiguous redirect" error.

Using this:

for file in `xargs --null -- < `find * -print0``

gives the following errors:
command substitution: line 26: syntax error near unexpected token `newline'
command substitution: line 26: `xargs --null -- < '

but then produces the output I'm expecting (i.e. a list of the output file
names (keeping in mind the actual processing part of the script is currently
commented out) with the exception that "find" is the first entry in the list
and "-print0" is the last entry in the list; somehow the variable $OUTFILE
appears to be getting the values "find" and "-print0" at the beginning and
end of the loop.

I seem to be just going around in circles here. Any suggestions will be
greatly appreciated.

Thanks in advance,
Rodney Baker VK5ZTV

I have great faith in fools -- self confidence my friends call it.
-- Edgar Allan Poe
< Previous Next >