[ubuntu-uk] Bash and Path checks

Cornelius Mostert corneliusmostert at googlemail.com
Fri Apr 17 12:10:51 BST 2009


Hallo

I wrote my first Bash script!
However I am struggling to find a way to test if 2 paths are the same:
1. I use a for loop to run through a set of folders in a path (lets
say /home/myFiles/)
2. Now Test if the File Extension is = "mpg"
2.1. If true then I would like to know if the path of the previous mpg
file is the same as this mpg file
2.1.1. If != then I would like to create a few dirs in this new path

So script looks like:
for file in 4StartPath do
  fileExt = (get the file extention from 4file)
  if [ $fileExt = 'mpg' ]
  then
    newPath = (get File Path form $file)
    if [ $newPath != $oldPath ]
    then
      mkdir $newPath\Sound
      mkdir $newPath\Sound\MP3
      mkdir $newPath\Sound\wav
    fi

ffmpeg ding dong grab the MP3 and the Wav

mv mp3 and wav file to directories created
....

Obviously this is not the Exact script but i am struggling to do the
"if [ $newPath != $oldPath ]" bit

as I am new to bash scripts a code snippet would be nice and as I
would like to know what the code does could you explaine it to me as
well :-)


Pretty please



More information about the ubuntu-uk mailing list