Computing.Net > Forums > Programming > Menu in Unix

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Menu in Unix

Reply to Message Icon

Name: morava
Date: March 18, 2009 at 01:09:13 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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 ;;



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 18, 2009 at 09:45:52 Pacific
Reply:

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


0

Response Number 2
Name: morava
Date: March 18, 2009 at 11:46:46 Pacific
Reply:

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


0

Response Number 3
Name: nails
Date: March 18, 2009 at 12:33:55 Pacific
Reply:

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


0

Response Number 4
Name: Ravey Dave
Date: March 19, 2009 at 15:59:04 Pacific
Reply:

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.


0

Response Number 5
Name: nails
Date: March 19, 2009 at 16:28:40 Pacific
Reply:

Hey Ravey Dave!

Good catch! You have a good eye.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Menu in Unix

Decompile java in unix www.computing.net/answers/programming/decompile-java-in-unix/6044.html

File Seperation in Unix www.computing.net/answers/programming/file-seperation-in-unix/18065.html

How to read/write data in UNIX Format (.NET) www.computing.net/answers/programming/how-to-readwrite-data-in-unix-format-net/19942.html