The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-15-2002
ruffenator ruffenator is offline
Registered User
  
 

Join Date: Jan 2002
Location: uk
Posts: 23
help please

hi ya just needed some help to validate this badboy
what i need is that the user enters a directory then it'll change to that and then print the directory. if not a valid directory the user is aksed whether they want another go, if yes they have another go, if not they menu programme reruns again. please help me !
ta


"3")
42
43 clear
44
45 print "this will change your current working directory"
46
47 print "please enter a directory to change to"
48
49 read dir junk
50
51 if test -d $dir
52
53 then
54
55 clear
56
57 echo "The directory $dir does exist"
58
59 echo "I will now change to that directory"
60
61 cd $dir
62
print -n "You are now in the" "directory :"
64
65 pwd
66
67 echo "Please push enter to continue"
68
69 read
70
71 /home/bf01/bf01iaru/projcp/proj/
72
73 else
74
75 if test -f $dir
76
77 then
78
79 clear
80
81 echo "$dir is a file not a directory"
82
83 else
84
85 clear

87 echo "$dir does not exist"
88
89 echo "Please try again"
90
91 sleep 3
92
93 /home/bf01/bf01iaru/projcp/proj
94
95 fi
96
97 fi
98
99 ;;
100
  #2 (permalink)  
Old 01-16-2002
kanang kanang is offline
Registered User
  
 

Join Date: Dec 2001
Location: kuala lumpur
Posts: 21
"if $dir isn't a valid directory" we say

if [ ! -d $dir ]
then
...

fi
  #3 (permalink)  
Old 01-16-2002
ruffenator ruffenator is offline
Registered User
  
 

Join Date: Jan 2002
Location: uk
Posts: 23
thanks but that doesn't answer my question any other help would be great. remember if the input isnt ma directory then they are given the question do you want another try? if yes they have another go if no then it reloads the project again.
ta
  #4 (permalink)  
Old 01-16-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
The first thing I can suggest is to make your code more organized. Just looking at this (with line numbers and all - even though we're missing the first 40-some lines) makes my eyes want to roll back in my head...
You can do it to fit your own style, but indenting can be your friend - for example:

Code:
(...)
read dir junk
if [ -d "$dir" ]; then
        echo "The \"$dir\" directory is valid."; cd $dir
        echo "You are now in `pwd`"
else
        echo "The \"$dir\" directory is not valid"
        echo "You are still in `pwd`"
fi
(...)

I don't know about you, but that's way easier for me to read... It groups each step together, so you can pretty much see what's going on in a glance.

Right now I am assuming this is homework, so I'm not going to give anything away - especially using somethng you may or may not have learned yet. But here's a hint for looping in a menu script (besides the ones mentioned other places in the forum):
use a "while" construct, and tell it to loop (almost) forever... that way, at the end of the command, it simply restarts.

Hope it helps.
  #5 (permalink)  
Old 01-16-2002
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,829
Yes, ruffenator has published many homework problems this week and we've had to spend time chasing them down and deleting them (wasting time).

Homework problems on the boards are against board rules and help keep the forums professional, without ethical problems.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0