veprory simple but frustrating for a newbie shell script question
ok im writting this script for a class that I am taking and I am stuck. Its basically a "sophisticated address book"(something that I would think a shell script is not for primarily..anyways) when i get the information for the user ...my idea was to create a file with the name of the person and then in it put the phone number...something like this:
result=0 result= grep $fname??? | wc -l if [ $result==0 ] then if [ $result==0 ] then echo "Enter Name" read name touch $name.ls echo "Enter Number" read numb else echo Entry Already Made : $result fi ;; PROBLEM cant seem to find a way to "pipe" a way to send the content of $numb inside the $name.ls file. I have tried to cat>$name.ls but when I run it waits for me to input ... HELP i know this is very .... but im am a newbie...also I am having problems when i grep to find the file name...also waits for input ..is there something that i am missing Thanks for your time marigb |
echo $numb > $name.ls
|
YAYYYYYYYY
Thank you thats one less "thing" to worry about.... THANK YOU THANK YOU FOR YOUR TIME now if i could get that grep to work.... |
What are you trying to grep?
Want number of lines in a file that's name is stored in variable fname? Code:
wc -l < $fname Code:
result=$(wc -l < $fname) |
ok well i have made adjustments to the code...I am just looking if that "person" in this case file exists..aka there is one entry already
I tried the following: result=0 result=$( grep $testname.ls|wc -l) if [ $result==0 ] then echo "Enter Name" echo $result read name touch $name.ls echo "Enter Number" read numb echo $numb >$name.ls else echo Entry Already Made : $result fi but when i run it after i enter the first name the scripts just sits there as if expecting some input.. I am thinking its because of the grep?? |
Do you want to look inside the files?
replace your 'if [ $result==0 ]' (and all above it) with Code:
if grep -q $testname $fname Or do you want to check if a file $testname.ls exists? Use line Code:
if [ -e $testname.ls ] See 'conditional expressions' in man bash for more details. |
well my goal is to check for the existance of the file ...but nothing has worked
i know it may be something to do with the if .... anyways thank you for the ideas |
well after some changing around and with some other examples i have this now:
1)echo "Enter Name" read testname if [ f $testname.ls ] then echo "File Already Exists" else touch $testname.ls echo "Enter Number" read numb echo $numb >$name.ls fi ;; notice the f...and the space..I had a look at one example that did it this way ...when i run it ...i get the error in the if statement :unary operator expected but if i remove the space...then it will just take the if as true and always go through there |
no.
You didn't read the conditional expressions in man bash *and* you didn't read my previous post. This is boring.. not 'if [ f foo ]', but 'if [ -f foo ]', as in my example. Why -f this time, and -e on the previous? See the 'conditional expressions', in bash manual page. What does the last sentence mean? Type: 'man bash' and look for the section that has a title 'CONDITIONAL EXPRESSIONS'. Or read an online version. EDIT: .. or maybe you did read those. I'm just too tired right now and go back to sleep... |
well i am sorry if this is boring ... I DID read the man's but it doesnt make sense to me ... Thank you for all your help but this is hard stuff for someone who has basically has self taught LInux in less than 2 months and is expected to write a shell script ..I have no books just the man and online resources...Anyways thanks for your help...I will try to figure it out
|
You are progressing quite well for studying all in two months.
Sorry for being aggressive. I just were too tired last night. It is just sometimes hard to distinquish unwilingness to read a manual and situation where manual is read, but it wasn't helpful from eachother. My mistake. This is a newbie forum afterall. |
update:
got everything to work...just need to fix a few things here and there..mostly pretty things up.. but everything seems to be working..I do appreciate your help and patience.... marigb |
All times are GMT -5. The time now is 11:11 AM. |