Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Shell scripts

Posted on 2002-06-05
7
Medium Priority
?
221 Views
Last Modified: 2010-04-17
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
########################################################
0
Comment
Question by:Ned_Kelly
  • 3
  • 3
7 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7058863
> .. 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
 
LVL 24

Expert Comment

by:SunBow
ID: 7063729
done?
0
 

Author Comment

by:Ned_Kelly
ID: 7064509
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

Accepted Solution

by:
ahoffmann earned 150 total points
ID: 7064663
> cdfile=-/music
is this a typo? probably you meant
  cdfile=~/music

Also, did you follow **all** my suggestentions (please read again)
0
 

Author Comment

by:Ned_Kelly
ID: 7067004
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7067067
BTW, why grading with B?
0
 

Author Comment

by:Ned_Kelly
ID: 7067099
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Starting up a Project

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question