Can I add a command in bash that starts when I open it?

Lisa Kachold lisakachold at obnosis.com
Fri Oct 24 10:52:28 MST 2008


Yes, 

Just add it to the end of your .bash_profile
Should you want ALL USERS to have these great functions you create, you would edit the /etc/profile (optimally /etc/profile.local since the regular /etc/profile global profile file will be updated with patches, etc.  yet the local file is for optimizations.

Here's what it looks like when you can define it:

function temp( ) { cat /proc/acpi/thermal_zone/THRM/temperature; }

Here's some other great .bash_profile (or .bashrc) toys:
function calc() { echo "$*" | bc; }
function mktar() { tar czf "${1%%/}.tar.gz" "${1%%/}/"; }
function mkmine() { sudo chown -R ${USER} ${1:-.}; }

function newmail()
{
    tot=0
    for mb in $MAIL/*; do
        cnt=`ls -1 $mb/new/|wc -l`
        tot=`expr $tot + $cnt`
        echo "$(basename $mb):$cnt"
    done
    echo "Total:$tot"
}# sanitize - set file/directory owner and permissions to normal values (644/755)
# Usage: sanitize <file>
sanitize() {
    chmod -R u=rwX,go=rX "$@"
    chown -R ${USER}.users "$@"
}
then the last line would be where you invoke it:
temp

Reference: http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/getting-started-guide/s1-q-and-a-starting.html

http://wapedia.mobi/en/Obnosis |  http://en.wiktionary.org/wiki/Citations:obnosis | Obnosis.com (503)754-4452
> From: nathan at paysonlinux.org
> To: plug-discuss at lists.plug.phoenix.az.us
> Subject: Re: Can I add a command in bash that starts when I open it?
> Date: Thu, 23 Oct 2008 22:36:26 -0700
> 
> On Thursday 23 October 2008 22:16:46 Mike Hoy wrote:
> > Just out of curiosity can I have a command execute when I open command
> > line?
> >
> > Thought I would have:
> >
> > cat /proc/acpi/thermal_zone/THRM/temperature
> >
> > start up each time I opened it so I could check my temperature regularly.
> >
> > I searched for the answer and the closest answer I got was putting it
> > in /etc/rc.local, but that didn't work.
> >
> > Thanks,
> >
> > Mike Hoy
> > ---------------------------------------------------
> > PLUG-discuss mailing list - PLUG-discuss at lists.plug.phoenix.az.us
> > To subscribe, unsubscribe, or to change your mail settings:
> > http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
> 
> 
> 
> Simple. Add that command to your .bashrc file. Some shells use .profile 
> instead. Play around with that.
> 
> echo cat /proc/acpi/thermal_zone/THRM/temperature >> .bashrc
> 
> nathan
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss at lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change your mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

_________________________________________________________________
Stay organized with simple drag and drop from Windows Live Hotmail.
http://windowslive.com/Explore/hotmail?ocid=TXT_TAGLM_WL_hotmail_102008
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.PLUG.phoenix.az.us/pipermail/plug-discuss/attachments/20081024/bac3f27b/attachment.htm 


More information about the PLUG-discuss mailing list