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..
# 8  
Old 04-14-2008
Nope. I would suggest you change the input format so it doesn't require the parentheses.
# 9  
Old 04-14-2008
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
#ERROR line = 'grep $2 dirInfo'
sed -e 's/$line/$name $address $phonenumber/g' dirInfo
else
echo "not found."

Still having problems. Can I not assign grep output to a variable?
# 10  
Old 04-14-2008
Quote:
Originally Posted by Generic
Code:
#ERROR line = 'grep $2 dirInfo'

Still having problems. Can I not assign grep output to a variable?
try putting the grep instruction in backticks not single quotes. or use this form:
Code:
line=$(grep $2 dirInfo)

or

line=`grep $2 dirInfo`

# 11  
Old 04-14-2008
thanks very much for the reply

line = $(grep $2 dirInfo) #Gives the error: line: command not found
line = 'grep $2 dirInfo' #Gives the error: line: command not found

Is there a different way to replace the line (if $2 exists) that might be easier?
# 12  
Old 04-14-2008
You can't have spaces around the equals sign. But you might as well inline this into the sed script.

Code:
sed "s/.*$2.*/$name $address $phonenumber/" dirInfo

If you want to replace an existing entry in dirInfo, you need to save the result somewhere; this will merely print it. If your sed has the -i option, that's something you could explore.

However, this loses the information about whether the match was successful or not, so you might need to refactor it so that an error message can be printed if not. Maybe your grep idea was better after all.

You might want to anchor the search string a little better; if somebody says they want to replace "a" in the phone book, this will replace all lines containing the letter a anywhere in them.
# 13  
Old 04-14-2008
Thanks for the reply, i really do appreciate all help.

I couldnt get that to work though, as i encountered many different problems

I currently have:
Code:
#delete the line that include the name that they enter

sed '$a\'"$name         :$address               :$phonenumber" dirInfo

#sort and output file dirInfo

Basically im adding the users new input, but I still need to delete the original name.

I tried sed '/$2/d' dirInfo but that didnt work, any ideas?
# 14  
Old 04-14-2008
Quote:
Originally Posted by Generic
I tried sed '/$2/d' dirInfo but that didnt work, any ideas?
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"

 
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