Visit the LQ Articles and Editorials section
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-25-2004, 08:19 AM   #1
Gag Halfrunt
LQ Newbie
Registered: Nov 2004
Distribution: Mandrake/Knoppix
Posts: 24

Rep: Reputation: 15
How do I add a function to Bash?

Is it possible to add a function to bash-- I mean, say, making a command called 'joe' that launches Gaim, Xchat and Firefox?

What about more elaborate things, like opening a blank KWrite window and saving it as ~/diary/dd_mm_yyyy.txt?
Old 11-25-2004, 08:35 AM   #2
Senior Member
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96

You'll have to script these things. Put the following into an empty text file (called 'joe' if you like):
gaim &
xchat &
then make the file executable. You can either run the script from the directory it's in with './joe' or put the file in a directory in your $PATH (~/bin is usually a safe bet) and just run 'joe'

The second example I would do as:
touch ~/diary/`date +%d`_`date +%m`_`date +%Y`.txt
kwrite ~/diary/`date +%d`_`date +%m`_`date +%Y`.txt
again in a file made executable.

Old 11-25-2004, 08:45 AM   #3
Registered: May 2004
Distribution: Ubuntu
Posts: 583

Rep: Reputation: 33
careful tho, "joe" is "joe's own editor" a text editor, so be careful to name it something else if putting it in your path (if you have joe installed )
Old 11-25-2004, 11:54 AM   #4
Senior Member
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
You could also use a Bash alias. Try typing this:
alias joe='gaim & xchat & firefox &'
Then simply type joe to execute the alias.

You put aliases in your ~/.bashrc so they're always accessible (if you have ~/.bashrc sourced from your ~/.bash_profile).

Old 11-25-2004, 01:01 PM   #5
Registered: Jun 2004
Location: Germany
Distribution: Debian (testing)
Posts: 276

Rep: Reputation: 33
Instead of moving the script into my path, I normally just simlink them to my path. I.e., I have a folder of Scripts in my home directory (for easy editing and transport to other machines) and when I want one installed on my system I do something like:

ln -s /home/optimistic/scripts/ /usr/bin
Then it is just a matter of typing myscript at the command line, or in my case, I have a section of my Fluxbox menu devoted to scripts like this:

[submenu] (Scripts){}
      [exec] (myscript1) {myscript1}
      [exec] (myscript2) {myscript2}
Old 11-25-2004, 01:05 PM   #6
Registered: May 2004
Distribution: Ubuntu
Posts: 583

Rep: Reputation: 33
I have a scripts folder then add that folder to the path

But for binaries installed somewhere in /home I symlink to path instead of anything else.


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
Simple Bash function mijohnst Programming 13 10-23-2005 01:40 PM
To add mouse scroll function satimis Linux From Scratch 2 09-22-2005 10:06 AM
Bash function pazvant Linux - Software 1 03-08-2005 08:47 AM
stat function in BASH... PokerFace Programming 1 11-04-2002 12:31 PM
GOTO function in bash? sobchak Programming 1 07-22-2002 06:10 AM

All times are GMT -5. The time now is 10:59 AM.

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