LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using a function (https://www.linuxquestions.org/questions/linux-newbie-8/using-a-function-365736/)

Gald3r 09-21-2005 06:07 PM

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. :)

Tinkster 09-21-2005 06:45 PM

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

polrus 09-21-2005 06:51 PM

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

Gald3r 09-21-2005 06:52 PM

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.

Tinkster 09-21-2005 06:58 PM

Just get rid of the word function in front of your
function, then. ;}



Cheers,
Tink

Gald3r 09-21-2005 07:13 PM

Oops! Was it so simple? I'll try it then! :D

Gald3r 09-22-2005 10:30 AM

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 :(

Tinkster 09-22-2005 01:13 PM

Code:

today(){
        echo "Today is `date`"
}


Gald3r 09-22-2005 04:51 PM

The problem is solved :) You rock Tinkster!

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

functionname() {
commands....
}

:cool:


All times are GMT -5. The time now is 05:42 PM.