[sclug] Bash scripting help needed

Neil Haughton haughtonomous at googlemail.com
Tue Apr 21 19:30:30 UTC 2009


Hi,

I'm starting out (it had to happen eventually) on a bit of bash scripting.
It's simple task really, but I want to save myself a bit of repetitive
labour (as you do).

The trouble is it won't play, and I am stumped. Can anyone point me at the
error?

The purpose of the script (for your interest) is to concatenate all the
audio files in a given folder into one big uninterrupted file. If I rip one
of my classical CDs the music is annoyingly split into 'tracks', which is
fine for rock or pop, but irritating when the music is intended to be one
long piece.

My script to deal with this (named audiojoin) is located in /usr/local/bin
(on my PATH) and I have chmod-ed it to u+rx, and chowned it to be owned by
me. If I plonk myself in a shell in another directory where the source files
are and execute the script, I get a series of errors that I do not
understand.

Here's the script contents:

#! /bin/bash

if ["$1" -eq ""]; then
echo "Use: command codectype outputfilename"
exit
fi

if ["$2" -eq ""]; then
echo "Use: command codectype outputfilename"
exit
fi

echo "codec type=$1"
echo "output file=$2"

#build a list of the files in the current directory
fileList=""
for f in $(ls ./); do
 fileList="$fileList \"$f\""
done

#now join them all together into one big audio file
`shnjoin -o $1 $fileList`

#rename the result as asked
mv joined.$1 $2.$1
#end of script

So I execute it with (say):

$audiojoin flac Act1

and I should end up with all the .flac files in the current directory
concatenated into a single file called Act1.flac

Here's the console output:

/usr/local/bin/audiojoin: line 3: [flac: command not found
/usr/local/bin/audiojoin: line 8: [Act1: command not found
codec type=flac
output file=Act1
shnjoin: warning: cannot open non-existent file: ["01.flac"]
shnjoin: error: could not open file: ["01.flac"]
mv joined.flac Act1.flac


Questions:

1. Why the two "command not found' messages?
2. Why the "cannot open non-existent file" warnings when the files do indeed
exist in the current directory (from where I launch the command), which by
the way is in my home folder?

I should add that if I 'echo' the shnjoin line and then copy and paste the
resulting echoed output at the prompt, it executes correctly - just not from
the script. eg

shnjoin -o flac "01.flac" "02.flac"

works fine if I do it myself.

It's almost as if the script executes in the context of its own directory,
not the directory where I launch it, which would explain why it cannot find
the files listed in the $fileList variable.

Any ideas?

TIA

Neil.



More information about the Sclug mailing list