Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Select statement

Posted on 2005-04-10
1
Medium Priority
?
591 Views
Last Modified: 2008-02-01
What is wrong with this script!?!?!

I'm trying to write a script that does the following:
select choice in "Clear Screen" "Find & Delete all files ending in .tmp" "Find & Move all files not modified in last 2 weeks" "Display a long listing of a subdirectory" "Exit"

Here is my script:
$cat select
#!/bin/ksh
# Menu-driven user script
#
oldfiles=$HOME/oldfiles
#
# If oldfiles directory doesn't exist, create it
#
if [[ ! (-d $oldfiles) ]]
then 'mkdir' $oldfiles
fi
#
select choice in "Clear Screen" "Find & Delete all files ending in .tmp" "Find & Move all files not modified in last 2 weeks" "Display a long listing of a subdirectory" "Exit"
do
 case $choice in
   "Clear Screen")
       clear;;
   "Find & Delete all files ending in .tmp")
       find $HOME -name '*.tmp' -exec rm -i {} \;;
   "Find & Move all files not modified in last 2 weeks")
       find $HOME –mtime +14 –exec mv –i {} /oldfiles \;;
   "Display a long listing of a subdirectory")
        read 'filelist?Enter files to display: '
        find $HOME –name $filelist –exec ls –l {} \;;
   "Exit")
        break;;
   *) echo Invalid choice; please try again;;
esac
done
#
exit 0

when I execute the script I get this message:
$ ./select
./select[19]: syntax error: `)' unexpected
$

I've done everything I can think of and nothing works. Any ideas??
0
Comment
Question by:nrstahl
1 Comment
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 13750019
The problem is the find/case terminators.

Each case statement needs to be terminated by ;;

On the lines where you have 'find', you only have a single ;

I don't know if your cut/paste stuffed your formatting, but it makes it hard to read and debug.

#!/bin/ksh
# Menu-driven user script
#
oldfiles=$HOME/oldfiles

#
# If oldfiles directory doesn't exist, create it
#
if [[ ! (-d $oldfiles) ]]
then
  mkdir $oldfiles
fi
#

select choice in "Clear Screen" "Find & Delete all files ending in .tmp" "Find &
 Move all files not modified in last 2 weeks" "Display a long listing of a subdi
rectory" "Exit"
do
case "$choice" in
"Clear Screen")
        clear
        ;;
"Find & Delete all files ending in .tmp")
        find $HOME -name '*.tmp' -exec rm -i {} \;
        ;;
"Find & Move all files not modified in last 2 weeks")
        find $HOME .mtime +14 .exec mv .i {} /oldfiles \;
        ;;
"Display a long listing of a subdirectory")
        read 'filelist?Enter files to display: '
        echo find $HOME -name $filelist -exec ls -l {} \;
        ;;
"Exit")
        break
        ;;
*)      echo Invalid choice; please try again
        ;;
esac
done


0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

580 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