Solved

Shell scripts

Posted on 2002-06-05
7
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Introduction to Processes

636 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