Project with somewhat simple bourne shell cript..


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Project with somewhat simple bourne shell cript..
# 15  
Old 04-14-2008
Quote:
Originally Posted by era
Again, don't use single quotes if you want variables to be expanded; use double quotes.

This will still delete all lines which contain the argument string anywhere in them; perhaps you would be better off if you required the argument to match the entire first field, exactly.

Code:
sed "/^$2:/d"

It seems like I have tried every possible thing. Smilie when I do exactly what you suggested it just acts like a cat (when the user is inputing information, it keeps going until i press ctrl+d). If I can just figure out how to delete the line containing the pattern of $2 (first and last name) than id be fine.

Thanks for any/all help.

could it have anything to do with the quotations that get entered as input?

Last edited by Generic; 04-14-2008 at 09:21 PM..
# 16  
Old 04-15-2008
Do you have both first and last name in "$2", or do you need to put in "$2 $3" (or some variation, maybe "$3, $2"?)

Try temporarily echoing the parameters' values near the beginning of your script so you can see what is getting passed in in $1, $2, etc.

Code:
echo "######## \$1 is '$1'"
echo "######## \$2 is '$2'"
echo "######## \$3 is '$3'"

# 17  
Old 04-15-2008
Thanks for the reply, my current code:

Code:
elif [ "$1" == "-r" ]
then
echo "Enter the new name: "
read name
echo "Enter the new address: "
read address
echo "Enter the new phone number: "
read phonenumber

#Delete is not working
sed "/^$2:/d"

#Outputs new name and information, then sorts the whole list
sed '$a\'"$name         :$address               :$phonenumber" dirInfo | sort

else
echo "not found."
fi

To run the program: ./phonebook -r "Anderson, Thomas"

echo $1 outputs -r
echo $2 outputs Anderson, Thomas
# 18  
Old 04-15-2008
But you are still not saving the output of sed anywhere!

If your sed supports the -i option, that's convenient. Otherwise, something like

Code:
(sed -e '$a\'"$name :$address :$phonenumber" -e "/^$2:/d" | sort -o dirInfo) <dirInfo

allows you to do it without saving to a temporary file. (Or use a temp file if that looks scary, by all means.)
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Cybersecurity

'Shell Shock' vulnerability in Bourne shell

A severe vulnerability was discovered in Bourne shell. Just google for: bash vulnerability ... for more details. (5 Replies)
Discussion started by: Cochise
5 Replies

2. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies

3. Shell Programming and Scripting

Bourne/C shell help

Exercise Five Write a Bourne shell script which: • Professionalism: plan for this from the start. • Has one command line argument. • If the command line argument is a directory then the script should output the number of files in the directory. • If the command line argument is an ordinary... (2 Replies)
Discussion started by: moesom
2 Replies

4. Shell Programming and Scripting

Xapture Plsql Error from Unix Shell cript

Hi Friends, Need your help . I have a shell script which executes the plsql procedure proc_p1. I want to capture the error message when the procuder throws some error message. I codeed in the following way . But it shows Job Success. Kindly anyone give some better idea to over come this ... (2 Replies)
Discussion started by: imipsita.rath
2 Replies

5. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

6. Shell Programming and Scripting

I need to understand the differences between the bash shell and the Bourne shell

I do not claim to be an expert, but I have done things with scripts that whole teams of folks have said can not be done. Of course they should have said we do not have the intestinal fortitude to git-r-done. I have been using UNIX actually HPUX since 1992. Unfortunately my old computer died and... (7 Replies)
Discussion started by: awk_sed_hello
7 Replies

7. UNIX for Dummies Questions & Answers

Bourne-again shell

Hi guys !! well i'm still new in learning UNIX , and actually i'm still studying it by myself .. anyway, some people told me the Bourne-again shell is a good version of UNIX to work on , and i tried to download yesterday but i didn't know how to start it ...... the ReadMe file associated with... (3 Replies)
Discussion started by: mrsamer
3 Replies

8. Shell Programming and Scripting

simple Bourne problem

Hi, I'm a newer for this languages, and I have a log file, which is something like this: 35.75.253.207 - - "GET /products/orgonizer/title.png HTTP/1.1" 200 1555 "-" "Mozilla 1.4" Now, I want to write a shell code to accoplish like ./XXX.sh -N n n is a number by user input, the code should... (5 Replies)
Discussion started by: pnxi
5 Replies

9. Shell Programming and Scripting

simple bourne script

Hello There, I am trying to write this SIMPLE script in Bourne Shell but I keep on getting a blank response. Can you see what I am doing wrong? I am simply trying to take the day of the week from our system and when the teachers sign on I want them to see the message of the day, when they exe... (2 Replies)
Discussion started by: catbad
2 Replies

10. UNIX for Advanced & Expert Users

Bourne shell script need help please ?

i have this assignment.. and i mad this script but there is something wrong with it.. if anyone can tell me.. watz going on... i would appreciate it.. tHnX in advance.. count=1 val=$2 op=$1 ans=0 if then if then while do ... (7 Replies)
Discussion started by: dezithug
7 Replies
Login or Register to Ask a Question