help please


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help please
# 1  
Old 01-15-2002
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  
Old 01-16-2002
"if $dir isn't a valid directory" we say

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

fi
# 3  
Old 01-16-2002
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  
Old 01-16-2002
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  
Old 01-16-2002
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.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question