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.
if statement problem
Name: fanco Date: October 16, 2007 at 12:03:08 Pacific OS: xp CPU/Ram: 512 Product: hp
Comment:
can anybody help me to fix my code i am trying to get default out put else "name is NOT listed" but evey time I run the program i cant get it thank u ============================================
echo "Enter the first letter of the name to look up, or q to quit" read name
while [ $name != "q" ]
do echo "Do you want to list all names start with $name {y|n} ?" read choice
if [ $choice = "y" ] then grep -i "^$name" /home/students/atammf/lab1/phonebook.list;
elif [ $choice = "n" ] then echo "Enter the full last name to look up: " read name1 grep -i -w "$name1" /home/students/atammf/lab1/phonebook.list;
Name: fpmurphy Date: October 16, 2007 at 17:30:47 Pacific
Reply:
Try the following syntax if you are using a POSIX or Korn shell
if [[ $choice = "y" ]]
i.e. [[ ..]] instead of [ .. ]
If you are using csh/tcsh or similar, try
if [ "$choice" = "y" ]
0
Response Number 2
Name: memyselfandadi Date: October 29, 2007 at 09:44:52 Pacific
Reply:
Hi Fanco, One Basic thing I see is, while comparing strings on UNIX, its always a good idea to cover it with " like this while [ "$name" != "q" ]; then... In the script that you have mentioned, the fact that $name is empty will transfer your script to something like this while [ != "q" ] and will result in a syntax error. Hope this helps. --
Summary: I need to create a script file that CVS can use to validate user comments. It must return 0 or 1 depending on whether the validation succeeds. I've tried the following: #!/bin/sh # # validatecomment...
Summary: I have a file that consists of a blank line, then either Y or N and then another blank line. I want to take this into an if statement saying if the file contains a Y then do this else do that. I've tr...
Summary: I have written a scipt that will report when a drive is down, but i finding if the status of the drive is UP, then "while read LINE" ignores the IF statement. I want the script to print the echo "Al...