Menu in Unix

March 18, 2009 at 01:09:13
Specs: Windows XP
hello, I am very new to Unix and I am working on a very hard assignment. I cannot figure out what the problem is ! I am working on a menu, a user should choose from, 5 options, but i am geting the error Command not found (script does have the x permission) Also I am not sure if i have the menu optoins set up correctly. Could someone please help me? I am in a state of panic
THanks !
Molly

#!bin/csh
# This menu will allow user to select from a menu of options, and then perform the
# selected command. User can use options until he chooses to exit

while :
do
clear
echo ***** Select from menu *****
echo "[1] List all files in the current directory"
echo "[2] Display today's date and time"
echo "[3] Display whether a file is just a file, or if it is a directory"
echo "[4] Create a back up file"
echo "[5] Exit the menu"
echo -n "Select your choice {1-5}:"
read yourch
case $yourch in
1) echo "These are your files: "; ls -l; echo "Press Enter"; read;;
2) echo "Today is 'date', time is 'time'; echo "Press Enter"; read;;
3) echo "Is the file a file or a directory?"; -a $1; echo "File is a file, not a directory"; read;;
4) echo "Create a backfile"; mv $; echo "Press Enter"; read;;
5) exit 0 ;;


See More: Menu in Unix

Report •


#1
March 18, 2009 at 09:45:52
The unix commands you were trying to implement were incomplete or I couldn't identify what you were doing. This at least gets the main menu working. You can probably change it from there:

#!/bin/csh

while :
do
   echo ***** Select from menu *****
   echo "[1] List all files in the current directory"
   echo "[2] Display today's date and time"
   echo "[3] Display whether a file is just a file, or if it is a directory"
   echo "[4] Create a back up file"
   echo "[5] Exit the menu"
   echo -n "Select your choice {1-5}:"
   read yourch

   case $yourch in
      1) echo "These are your files: "; ls -l; echo "Press Enter"; read x;;
      2) echo "Today is 'date', time is 'time'"; echo "Press Enter"; read x;;
      3) echo "Is the file a file or a directory?";  echo "File is a file, not a directory"; read x;;
      4) echo "Create a backfile";  echo "Press Enter"; read x;;
      5) exit 0 ;;
      *) exit 0;;
   esac
done


Report •

#2
March 18, 2009 at 11:46:46
Thanks ! I tried to correct it but still getting "Command not found" What this should is to allow user to select from a menu of 5 tasks and perform the selected task repeatedly until the user chooses to quit. The 3rd choice should tell the user whether the selected file is a file or a directory. This is what i have right now. Its still not working

#!bin/csh
# This menu will allow user to select from a menu of options, and then perform the
# selected command. User can use options until he chooses to exit

while :
do
echo ***** Select from menu *****
echo "[1] List all files in the current directory"
echo "[2] Display today's date and time"
echo "[3] Display whether a file is just a file, or if it is a directory"
echo "[4] Create a back up file"
echo "[5] Exit the menu"
echo -n "Select your choice {1-5}:"
read yourch

case $yourch in
1) echo "These are your files: "; ls -l; echo "Press Enter"; read x;;
2) echo "Today is 'date', time is 'time'"; echo "Press Enter"; read x;;
3) echo "Is the file a file or a directory?"; echo "File is a file, not a directory"; read x;;
4) echo "Create a backfile"; echo "Press Enter"; read x;;
5) exit 0 ;;
*) exit 0;;
esac
done


Report •

#3
March 18, 2009 at 12:33:55
As I said, I'm not much of a csh scripter. I can tell you excuting:

ls -ld <filename>

gives:

if it's a directory, the first character is a "d'
if it's a file, the first character is a "-"

This code snippet gets the first character into variable my char:


#!/usr/bin/csh

set mychar=`ls -ld mydir|cut -c 1`
echo $mychar


Report •

Related Solutions

#4
March 19, 2009 at 15:59:04
morava, look at your first line

#!bin/bash

and look at nails first line

#!/bin/bash

can you see the difference. Hope that helps

Ravey Dave.


Report •

#5
March 19, 2009 at 16:28:40
Hey Ravey Dave!

Good catch! You have a good eye.


Report •


Ask Question