![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Scripting question | Katkota | UNIX for Dummies Questions & Answers | 6 | 01-13-2009 04:32 PM |
| FTP access & control question | Katkota | UNIX for Dummies Questions & Answers | 2 | 12-21-2007 10:23 AM |
| Scripting question | gonzotonka | SUN Solaris | 1 | 04-27-2006 08:04 PM |
| scripting question | carlvernon | Shell Programming and Scripting | 10 | 04-21-2006 07:42 AM |
| Scripting Question | damielle | Shell Programming and Scripting | 1 | 12-06-2001 05:13 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Control structures and scripting question..
Hey guys, I'm currently working on a project for comp sci course, and I'm very green to Unix and scripting, and only have a semesters worth of programming knowledge (bare with me! sorry!). What I'm trying to do is make a 'if ... then ... fi' control structure that takes user input and then searches the file where data is going and if the name already exists in first field it prints error msg (cant have two of same name in data file) So basically its sort a mock inventory auto parts management script, user goes to add new parts, first is prompted to enter name of part ... I then want to compare user input to first field of all entires already in my data file (auto.parts) ... if the part exists print error message, if not continue and add part to data file. So far I got: Code:
#bin/sh
echo -n "Please enter auto part name:"
read apname
if [ "$apname" = "$1" ]
then
echo -n "Part already exists! Can not enter duplicate parts."
stop=1
else
echo -n "Please enter operator's name:"
read opname
status="Part Available"
cdate=""
bname=""
fi
echo ${apname}:${opname}:${status}:${cdate}:${bname} >> auto.parts
echo "A new auto part has been added to inventory!"
It seems to not be comparing the user input to first field (first field is where auto part name goes i.e <partname>:<stuff>:<stuff>:<etc..>), it just ignores the statement and continues on ... allowing me to enter 100 Brake:etc:etc:etc lines if I wish too, which it shouldn't!. I'm almost positive i'm using wrong syntax in my if [statement]. ANY help, or finger pointing me to a great website for beginners would be MUCH appreciated!! Thanks guys! |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|