LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 11-25-2004, 07: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, 07:35 AM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi.

Sure,
You'll have to script these things. Put the following into an empty text file (called 'joe' if you like):
Code:
#!/bin/bash
gaim &
xchat &
firefox
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:
Code:
#!/bin/bash
touch ~/diary/`date +%d`_`date +%m`_`date +%Y`.txt
kwrite ~/diary/`date +%d`_`date +%m`_`date +%Y`.txt
again in a file made executable.

Dave
 
Old 11-25-2004, 07:45 AM   #3
ror
Member
 
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, 10:54 AM   #4
hw-tph
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).


Håkan
 
Old 11-25-2004, 12:01 PM   #5
Optimistic
Member
 
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:

Code:
ln -s /home/optimistic/scripts/myscript.sh /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:

Code:
[submenu] (Scripts){}
      [exec] (myscript1) {myscript1}
      [exec] (myscript2) {myscript2}
[end]
 
Old 11-25-2004, 12:05 PM   #6
ror
Member
 
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.
 
  


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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
Open Source Consulting | Domain Registration