LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-18-2012, 10:01 AM   #16
asistant
LQ Newbie
 
Registered: Oct 2003
Location: Ankara
Distribution: Redhat
Posts: 17

Original Poster
Rep: Reputation: 0

Quote:
Originally Posted by konsolebox View Post
How do you add record to the address book and how do you send a personalized greeting? I mean the commands.
konsolebox, I am still working on this part. I think I am good about setting up the script logic so I will work on each function.
 
Old 04-18-2012, 10:42 AM   #17
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,655

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
#Make arguments global to the script.
Whilst this is a solution I would consider it a step in possibly the wrong direction. What NA and I tried to point out is that a function receives parameters exactly the same way your script does.
What this means is:

1. for a script:
Code:
./script "tada"
Here we have the first parameter with a value of "tada" and it can be referenced in the script (notice underline) using $1

2. for a function:
Code:
foo()
{
    echo "$1"
}

foo

foo "bar"
If you test the above function in a script, which may or may not be called with any parameters, the first call to the function 'foo' will yield a blank line as no parameter was passed to the function,
however, the second call will echo the string "bar" on its own line as it is the first parameter passed to the function 'foo'.

If you then put it all together, ie. point one and two, and call the script in part two like so:
Code:
./script "tada"
The code output will be:
Code:
           < this is a blank line
bar
Notice the first line is blank ( I had to add the additional information after < as the formatting didn't show the line ) and there is no mention at all of the string "tada".

Last edited by grail; 04-18-2012 at 10:45 AM.
 
1 members found this post helpful.
Old 04-19-2012, 08:39 AM   #18
asistant
LQ Newbie
 
Registered: Oct 2003
Location: Ankara
Distribution: Redhat
Posts: 17

Original Poster
Rep: Reputation: 0
Thank you grail it helped me understand better.
 
  


Reply

Tags
logic, parameters


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
[SOLVED] bash script sed -r -i and -e parameters charu Programming 10 05-06-2011 07:28 AM
nested loop-bash script- issue on logic yathin Linux - Newbie 6 05-31-2010 07:30 AM
Passing parameters to bash script Kamikazee Programming 4 10-01-2005 07:41 AM
Passing Parameters to Bash Script mooreted Linux - Software 3 04-05-2004 10:08 PM


All times are GMT -5. The time now is 11:15 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration