PDA

View Full Version : custom .bashrc files



tehchad
15th January 2009, 11:57 PM
Okay, so I'm reading up on bash and it's a sick little environment! I'm just into learning aliases and beginning script writing. What I'm thinking is a thread for everyone to post their modifications to this file and why they like their specific changes. I've searched the older posts and have found nothing. I know there are several posters here who have been using linux since before linux existed, so there should be some good discussion and learning. Which is what I need!

GOGOGOGOGOGOGOGOGOGOGOGOGOOOOOO :D:D:D:D:D:D

pwca
16th January 2009, 12:06 AM
Try google with the search:

".bashrc"

There will be more than you can handle as far as reading material goes.

tehchad
16th January 2009, 12:11 AM
did that! poking through it now.

RupertPupkin
16th January 2009, 12:17 AM
The ~/.bashrc file is usually used for setting command aliases, while the ~/.bash_profile file is usually used to set environment variables. Anyway, here's what I have in my .bashrc:

alias rm='rm -f'
alias cp='cp -i'
alias mv='mv -i'
alias ls='ls -aF --color'
alias df='df -Th'
alias grep='grep --color=auto'
alias ps2pdf='ps2pdf14 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -dPDFSETTINGS=/printer'
I like the colored grep, which makes it easier to see the pattern matches. And the ps2pdf alias ensures that all fonts get embedded when I convert Postscript files to PDF (otherwise your PDF document may look very different than you intended).

stevea
16th January 2009, 01:58 AM
The ~/.bashrc file is usually used for setting command aliases, while the ~/.bash_profile file is usually used to set environment variables. ....

You forgot to say why. aliases are NOT inheritable from process to process so they MUST be in a "per shell" initialization file like .bashrc

exported variable are part of the process environment passed from parent process to child (unless changed explicitly)., so you can (and *SHOULD* only set this once at the login shell and let other processes inherent the environment.

Anyway shell aliases are deprecated. It is suggested that you use the more powerful shell functions instead.

mv() { /bin/mv -i $*; }
instead of
alias mv='mv -i'

==

One should use aliases sparingly. At one time I used a similar feature extensively and made a rather custom, terse, intricate set of commands for most of my daily cli usage. Then the big headache is you log into another system and you can barely remember the commands to do basic things or the options to these. One can become too dependent on excessive aliases (and functions and scripts).

The cases where they make good sense are in Rupert's list. To
A/ add an option flag for safety reasons "rm -i"
B/ eliminate the necessity of typing a *few* long complex commands (his pdf command)

My .bashrc and .bash_profile are unmodified and I've used sh ,ksh, csh, bash for decades.

I *DO* have a global profile in /etc/profile.d which UNDEFINES some aliases ((I dislike the color option for "ls" for example)) and sets an additional directory on PATH.

I DO have ~50 scripts to perform specific functions but these are usually complex functions and sometimes ones where I would not want to make a typo and ruin the command. File backups via rsync, setup a vpn tunnel, build a Fedora package from source. Somtimes just a method to record a sequence of commands I'll probably forget the details when I need it again in a few months (re-signing x509 certificates using openssl for example).