LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-09-2011, 01:19 AM   #16
trintukaz
Member
 
Registered: Sep 2011
Posts: 82

Original Poster
Rep: Reputation: Disabled

anyone?
 
0 members found this post helpful.
Old 10-09-2011, 01:20 AM   #17
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,826

Rep: Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973
Again, test the contents of the variable first, in the shell, and only run the command if it has the value you want in it.
 
Old 10-09-2011, 01:39 AM   #18
trintukaz
Member
 
Registered: Sep 2011
Posts: 82

Original Poster
Rep: Reputation: Disabled
Can you write me an example. I almost finished work and I still can't solve this problem.
 
Old 10-09-2011, 01:46 AM   #19
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,826

Rep: Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973
:sigh:

It's a simple if test, one of the most basic parts of shell scripting.

http://mywiki.wooledge.org/BashGuide..._and_.5B.5B.29

Go back to the start and read through the whole guide too, while you're at it.

Now please stop asking us to do your work for you, and try to learn something. We've given you everything you need to figure out your problem...so figure it out.

If, after really trying, you still can't quite make it work, post the code you have and we'll help you improve it.
 
1 members found this post helpful.
Old 10-09-2011, 02:02 AM   #20
trintukaz
Member
 
Registered: Sep 2011
Posts: 82

Original Poster
Rep: Reputation: Disabled
If I asked write contact book script for me that would be "asking us to do your work for you", but I am asking just show solution for only one situation. Or maybe you don't know answer? Then just tell.
 
0 members found this post helpful.
Old 10-09-2011, 02:40 AM   #21
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,544

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
I can vouch for the fact that not only does David know the solution but could write it in several different ways.

However, he is trying to help you to learn not only how to solve this issue but also further ones. It seems quite obvious you want the solution
given to you and then when you hit the next problem you will also be back to have it solved for you as well.

As with most questions asked here, show us what you have tried and where you are stuck? You have been provided a number of links that
can help you solve this issue. I will provide yet another link:

http://tldp.org/LDP/abs/html/

This has more information on bash and the option to use an 'if' is included in its pages.
 
Old 10-09-2011, 02:51 AM   #22
trintukaz
Member
 
Registered: Sep 2011
Posts: 82

Original Poster
Rep: Reputation: Disabled
When you don't have a lot of time those links are useless.
 
0 members found this post helpful.
Old 10-09-2011, 05:20 AM   #23
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
try IF
like:
Code:
if ( [ "$fname" = "" ] )
then
... nothing...

elseif ( [ "$fname" != "" ] )
then 
... do the search/replace to the file

fi
and all the other fields ($sname $number $email) can be done like so.
 
0 members found this post helpful.
Old 10-09-2011, 05:42 AM   #24
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,544

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Quote:
When you don't have a lot of time those links are useless.
Hmmm ... now this sounds like homework that you have left to the last minute.
 
Old 10-09-2011, 06:00 AM   #25
trintukaz
Member
 
Registered: Sep 2011
Posts: 82

Original Poster
Rep: Reputation: Disabled
Nope. I hate when I don't finish job it is like headache ;D
 
Old 10-09-2011, 06:25 AM   #26
trintukaz
Member
 
Registered: Sep 2011
Posts: 82

Original Poster
Rep: Reputation: Disabled
Really please help i have been searching for solution half day. I need to make that $recnum should be for example 1-1000 else script do nothing because if I not enter any number it deletes all contacts.
 
0 members found this post helpful.
Old 10-09-2011, 10:47 AM   #27
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Code:
if [ -z $recnum ]; then
   echo "Invalid null record number entry"
   exit 1
fi
You would have found this in the link already posted for you, but I'll narrow it down for this case:
http://tldp.org/LDP/abs/html/testconstructs.html

Telling someone that you don't have time to read the answer is a bit insulting. Those who do have the answers for you had to take the time to do the reading so they would have the answers. It isn't obvious how your time is more valuable than theirs, especially given that you are the one who gets all of the tangible benefit from getting the answer.

--- rod.

Last edited by theNbomr; 10-09-2011 at 10:55 AM.
 
1 members found this post helpful.
Old 10-09-2011, 02:47 PM   #28
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,826

Rep: Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973
I enjoy helping people with their scripts, really I do ... but only if they appear to be really interested in learning what I have to teach, and are willing to meet me half-way.

What I do not appreciate is being used as free tech support. If that's all you're interested in, then go pay someone to do the work. It's not my fault or my concern if you're low on time.

I'm sure I'm not alone in this attitude.

It really comes down to the way you present yourself. A person I would enjoy helping would say things like this:


I read the link, but I don't quite understand it. Here's what I tried. I think it should output "foo", but it's not working for me. Where am I going wrong? <posts example code>

Thanks for your help. This is what I came up with, and it seems to work. Are there any problems with it? <posts example code>

I see, so if you "foo" the "bar", then the "baz" will "bum", right? But what happens if you "bar" the "foo", like this? <posts example code>


This person shows interest in learning, and is participating in a two-way conversation. I would go out of my way to research things so we could both learn.

On the other hand, here's what a person I wouldn't want to help sounds like:


I can't find what I need
Can you write me an example?
Do you know how to fix this problem?
Sorry. I don't understand.
anyone?
When you don't have a lot of time those links are useless.



He also doesn't post any work of his own, or display any evidence that he's read any documentation or tried any of the links or advice previously given. Such a person just sounds like a time-sink.


I think you really need to read Eric S. Raymond's excellent guide on how to properly ask questions:

http://www.catb.org/~esr/faqs/smart-questions.html

And please try to understand that I'm not saying these things to be rude, I'm saying them to help you. This is a community where people come together to help each other learn and solve problems. Present yourself in the right way, and you'll be amazed at how friendly and helpful we can be. But selfish and demanding behavior isn't welcome.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: replace a line in text file freeindy Programming 10 09-08-2011 12:08 PM
Bash search line and replace hex to binary ekim Programming 5 07-09-2011 01:24 AM
How to replace string pattern with multi-line text in bash script? brumela Linux - Newbie 6 04-21-2011 06:56 AM
Perl script to replace a line after finding a previous line Mark1986 Programming 1 02-28-2011 05:09 PM
how to replace line of file with another line using awk in shell script amit_pansuria Programming 3 03-29-2009 09:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration