Shell scripts

Hi Folks, I'm having a bit of trouble with my program.
The code below is part of a set of scripts that allow me to view, add and search for a cd from a file named music.
From the cdmenu I can enter 'a' and the cdadd will appear and let me enter the data, but it wont write the data to the file.
The cdlist script will show the music file but only for a brief few seconds.
The if statements in the cdadd file I have commented out because I keep getting an an error on the fi saying that it is an unexpected fi statement.
When I add a CD it comes up with the file music does not exist. The file is in the same directory where all the other files are and where I'm working from. I have also initiated a path with PATH=$PATH:.
I am a bit lost and any help would be greatly appreciated.
Regards Ned
####################################################
cdadd

 
trap "rm -/tmp/* 2> /dev/null; exit" 0 1 2 3
cdfile=-/music
looptest=y
while [ "$looptest" = y ]
do
      clear
      cursor 1 4; echo "Cd Collection"
      cursor 3 4; echo "Artist Name    : "
      cursor 4 4; echo "Cd Title       : "
      cursor 5 4; echo "Date Purchased : "
      cursor 6 4; echo "Cost           : "
      cursor 7 4; echo "Add Another? (Y)es or (Q)uit "
      cursor 3 21; read artist
      #if [ "$artist" = 'q' ]
       #  then { clear; exit }
      #fi
      cursor 4 21; read title
      cursor 5 21; read date
      cursor 6 21; read cost
      #if [ "$title" > "    " ]
         #then
echo $artist $title $date $cost >> cdfile
      #fi
      cursor read looptest
      #if [ "$looptest" = 'q' ]
      #   then { clear; exit }
      #fi
done
##############################################

cdmenu

 
cdfile=-/source/music
loop=y
while [ "$loop" = y ]
do
      clear
      cursor 3 12; echo "CD Collection"
      cursor 5 12; echo "V - View music file    : "
      cursor 5 12; echo "A - Add CD to list     : "
      cursor 5 12; echo "S - Search for title   : "
      cursor 6 12; echo "Q - Quit"
      cursor 10 32;
      read choice || continue
           case $choice in
                [Aa]) cdadd ;;
                [Vv]) cdlist ;;
                [Ss]) cdsearch ;;
                [Qq]) exit ;;
                *) cursor 14 4; echo "Invalid code"; read prompt ;;
           esac
done
#######################################################


cdlist
######################################################


clear
cursor 2 20; echo "CD Collection"
cursor 3 20;
awk -F: ' { printf "%-18s %-18s %s\t%s\n", $1, $2, $3, $4 } ' music
########################################################
Ned_KellyAsked:
Who is Participating?
 
ahoffmannCommented:
> cdfile=-/music
is this a typo? probably you meant
  cdfile=~/music

Also, did you follow **all** my suggestentions (please read again)
0
 
ahoffmannCommented:
> .. but it wont write the data to the file.
How did you verify this statement?
It writes to **a file**, not to the file ./music as you might wish, but to the file cdfile. Probably you want your command look like:
  echo $artist $title $date $cost >> $cdfile

> .. The cdlist script will show the music file but only for a brief few seconds.
if you mean approx. 1 for "few", that's ok ;-)
The reason is that the called script (cdlist) return immediately after printing to cdmenu which then does a "clear".
Probably you want to add:
   sleep 10
or
   read dummy
to the end of cdlist.

> .. saying that it is an unexpected fi statement
that's 'cause
   >> then { clear; exit }  <<
is invalid shell syntax

> When I add a CD it comes up with the file music does not exist ..
see my very first comment herein
0
 
SunBowCommented:
done?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Ned_KellyAuthor Commented:
Hi folks, thanks for your comments. I have fixed the cdlist by adding the sleep 10, thankyou for that.
I haven't been able to figure the figure the writing to file as yet.  I have tried a few alterations but none have worked.  I have also looked for cdfile but it is nowhere to be found.  I thought the line
cdfile=-/music
set cdfile to write to the music file.
They all exist in the same directory.
I'm also not sure about the if fi statements, as the notes I have show the statement as put in the above file, and you tell me it not a valid shell statement.
I'm missing something somewhere I would say.
Many thanks for your help.
Regards Ned
 
0
 
Ned_KellyAuthor Commented:
Hi ahoffmann, thankyou for your help.  I have managed to get them all going tonight at Tafe.  I also have to add a delete function, but I should be able to get that going by myself.  We have been given our assignment which you will no doubt here from me as I try to get it running properly.
I had to take out the ~ and just set it as cdfile=/common/tom/music  
This worked for all files.
Again many thanks ahoffmann.
I remember you from previous help.
Regards Ned
0
 
ahoffmannCommented:
BTW, why grading with B?
0
 
Ned_KellyAuthor Commented:
Because I was not able to work out all the problems I had in my scripts.  Now this might be that it was my fault, but I am not to know this as I am only just learning.  So my grading of B was to my way of thinking the right grade to give.  I don't doubt you are right, but I have no way of knowing this.  The class tonight, I spent two hours working out the  problems with the help of others and the tutor.  I was very happy to get them all working.
Again many thanks,
Regards Ned
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.