LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-21-2005, 07:07 PM   #1
Gald3r
LQ Newbie
 
Registered: Sep 2005
Location: Athens, Greece
Distribution: RedHat 9
Posts: 24

Rep: Reputation: 15
Using a function


Hello. I have found the syntax of the function and realised its importance in the ~/.bashrc file but I haven't found the way to use it. I just type it's name at the terminal's prompt but I get an error message. What shall I do? A simple example :
function today { echo "Today is `date`"}
Then after logging on again I open the terminal window and type today. I get error.
 
Old 09-21-2005, 07:45 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Can you please post the ~/.bashrc and show us how you invoke
(try to invoke) the function later on? It works for me ...


Cheers,
Tink
 
Old 09-21-2005, 07:51 PM   #3
polrus
Member
 
Registered: Oct 2004
Location: Poland
Distribution: yoper
Posts: 53

Rep: Reputation: 15
u can just add this line

alias today='echo "Today is `date`"'

to Your ~/.bashrc file and relogin and typing

today

will give u the proper result

i'm not sure if this is what u wanted
 
Old 09-21-2005, 07:52 PM   #4
Gald3r
LQ Newbie
 
Registered: Sep 2005
Location: Athens, Greece
Distribution: RedHat 9
Posts: 24

Original Poster
Rep: Reputation: 15
I simply add the " function today { echo "Today is `date`"} " line at the end of the ~/.bashrc file. My " alias " work perfectly in this way. Then after I log on again I type " today " in the terminal window. Thats all

p.s. Sorry for not copying here the code but I cannot use linux right now.

polrus : yes i already did that but I am curious to find how functions work Thank you anyway.

Last edited by Gald3r; 09-21-2005 at 07:54 PM.
 
Old 09-21-2005, 07:58 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Just get rid of the word function in front of your
function, then. ;}



Cheers,
Tink
 
Old 09-21-2005, 08:13 PM   #6
Gald3r
LQ Newbie
 
Registered: Sep 2005
Location: Athens, Greece
Distribution: RedHat 9
Posts: 24

Original Poster
Rep: Reputation: 15
Oops! Was it so simple? I'll try it then!
 
Old 09-22-2005, 11:30 AM   #7
Gald3r
LQ Newbie
 
Registered: Sep 2005
Location: Athens, Greece
Distribution: RedHat 9
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by Tinkster
Just get rid of the word function in front of your
function, then. ;}



Cheers,
Tink
I removed the word " function " but no success
 
Old 09-22-2005, 02:13 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Code:
today(){
        echo "Today is `date`"
}
 
Old 09-22-2005, 05:51 PM   #9
Gald3r
LQ Newbie
 
Registered: Sep 2005
Location: Athens, Greece
Distribution: RedHat 9
Posts: 24

Original Poster
Rep: Reputation: 15
The problem is solved You rock Tinkster!

p.s.This is the exact form in order to work....

functionname() {
commands....
}

 
  


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
Calling another function from a function using GTK geminigal Programming 4 07-11-2005 04:15 PM
what are the Hexadecimal function and ASCII function in Perl Bassam Programming 1 06-03-2004 02:44 AM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 02:31 PM
Is the wait function is the same as the sleep function ? Linh Programming 3 04-28-2004 01:39 PM
Perl exec function in linux (and system-function) nazula Programming 1 04-19-2004 01:21 PM


All times are GMT -5. The time now is 02:43 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