Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I actually found following one-liner on commandfu.com:

cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext"; } I have not come across a similar use of the () in bash before.

It seems that it creates the command cmdfu temporarily within the bash environment. Am I correct here? Or is it actually stored somewhere? Is there a name for this construct so I can read up on it?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

This is a shell function. If you create it at the command line, it will exist only for the current shell invocation. You can add the definition to a shell startup file (.bashrc, .bash_profile, etc) and it will make it "permanent".

If you search the bash(1) manpage for "Shell Function Definitions" you can see the syntax for defining shell functions. The section "FUNCTIONS" goes into more details of functions themselves.

share|improve this answer
    
You can also use functions inside scripts to organize and reuse code in the same way you'd use them in other languages. –  Dennis Williamson Nov 5 '10 at 2:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.