Re: Post your .bashrc!

Brilliant, muzieca. Ripping off smile

Re: Post your .bashrc!

rizzeh
Thank you. smile
I'm glad that you like it.
I hope it's useful. smile

Motorbike, Openbox, and Coffee addict.

--muzi--

Re: Post your .bashrc!

mine has grown over time. maybe someone will find something they like in here.

# ----------------
# ~/.rhowaldt_bashrc
# personal bashrc aliasses etc file
# ----------------

# Make it shorter
alias inst="sudo apt-get install -y"
alias update="sudo apt-get update"
alias upgrade="sudo apt-get upgrade"
alias uninst="sudo apt-get purge"

alias brc="gedit ~/.bashrc &"
alias rbrc="gedit ~/.rhowaldt_bashrc &"

alias q="exit"
alias c="clear"

# some ls options, with directories first
alias ls="ls --color --group-directories-first"
alias ll="ls -AlhF --group-directories-first"
alias la="ls -A --group-directories-first"
alias lc="ls -CF --group-directories-first"

# search
alias where="which"
alias what="apropos"
alias apr="apropos"
alias ff="find . -type f -name"

# navigation
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../../"
alias ......="cd ../../../../.."
alias fonts="cd /usr/share/fonts"
alias scripts="cd ~/scripts"

# what's with the typo?
alias unmount="umount"

# count the number of files in a folder
alias numfiles="echo $(ls -1 | wc -l)"

# Use human-readable filesizes
alias du="du -h"
alias df="df -h"

# XMMS2 is crap to type
alias muz="xmms2"
alias n="xmms2 next"

# I only use Telnet for Medieval
alias mval="telnet moo.medievalmoo.nl 1111"

# Automatically do an ls after each cd
cd() {
  if [ -n "$1" ]; then
    builtin cd "$@" && ls --group-directories-first
  else
    builtin cd ~ && ls --group-directories-first
  fi
}

# from the MOO-days
alias @verb="@script"

# Set some colors (ripped from kestrel @ crunchbang forums)
BLACK='\e[0;30m'
WHITE='\e[1;37m'
LIGHTGRAY='\e[0;37m'
DARKGRAY='\e[1;30m'
RED='\e[0;31m'
GREEN='\e[0;32m'
BLUE='\e[0;34m'
YELLOW='\e[1;33m'
PURPLE='\e[0;35m'
BROWN='\e[0;33m'
CYAN='\e[0;36m'
LIGHTBLUE='\e[1;34m'
LIGHTGREEN='\e[1;32m'
LIGHTCYAN='\e[1;36m'
LIGHTRED='\e[1;31m'
LIGHTPURPLE='\e[1;35m'
NC='\e[0m'              # No Color

HISTFILESIZE=100000000
HISTSIZE=100000

# CBBS MFDATA EXPERIMENT SHIZZLE
export MFDATA=/media/storage/#linux/mfdata

edit: for those of you curious about the @script thing, check out this thread: http://crunchbanglinux.org/forums/topic/13759/script/

Last edited by rhowaldt (2011-07-05 18:29:03)

104

Re: Post your .bashrc!

command line help for your own code!

I just wrote a new shell function and think some of you might like it. It is intended to give some automatic documentation for shell commands.

I had the idea when I saw some of you having an alias to cat a file called "~/.functions.help" and "~/.aliases.help". I thought: thats a lot of work to maintain such a file. why not go fore some RTFS documentation?

my first idea was to use this in functions

if [ "$1" = "--help" ] then type $FUNCNAME; fi

but i would have to write that code into every function i write.
so I wrote a function to open manpages or cat shellscripts or display function definitions automatically:

h () {
  for ARG; do
    case `type -t "$ARG"` in 
      alias) alias "$ARG";;
      keyword) type $ARG;;
      function) type $ARG;;
      builtin) help $ARG;;
      file) FILE=`which "$ARG"`
        case `file --mime --dereference --brief "$FILE"` in
      text/*|application/x-sh)
        if [ 50 -gt `wc -l <"$FILE"` ]; then cat "$FILE"
        else echo "$FILE is quite a long text file. I will not cat it."; fi
        ;;
      application/*)
        if man "$ARG" >/dev/null 2>&1; then
          man "$ARG"
        else
          echo "$FILE is a compiled executable or unsupported format."
          echo "It does not have a man page installed. Try '$FILE --help' or '-h'."
        fi
        ;;
    esac
    ;;
      *) echo "Error: '$ARG' not recognized." 1>&2;;
    esac
  done
}

enjoy
luc

Re: Post your .bashrc!

An edited one from someone else in this thread.

export EDITOR=nano
export PAGER=less
export VISUAL=nano

export HISTSIZE=10000
export HISTFILESIZE=${HISTSIZE}
export HISTCONTROL="ignoredups"

export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;38;5;74m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[38;5;246m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[04;38;5;146m'

PS1='\[\033[01;31m\][\[\033[01;30m\]\u\[\033[01;32m\]@\[\033[01;37m\]\h\[\033[01;31m\]] \[\033[01;31m\][\[\033[01;34m\]\w\[\033[01;31m\]]\[\033[01;32m\] \[\033[01;31m\][\[\033[01;32m\]$\[\033[01;31m\]]\[\033[01;37m\] '


# Check for an interactive session
[ -z "$PS1" ] && return

# bash aliases
[ -f ~/.bash_aliases ] && . ~/.bash_aliases

shopt -s checkwinsize
shopt -s histappend
PROMPT_COMMAND='history -a'

start()
{
  for arg in $*; do
    sudo /etc/rc.d/$arg start
  done
}
stop()
{
  for arg in $*; do
    sudo /etc/rc.d/$arg stop
  done
}
restart()
{
  for arg in $*; do
    sudo /etc/rc.d/$arg restart
  done
}
reload()
{
  for arg in $*; do
    sudo /etc/rc.d/$arg reload
  done
}

Re: Post your .bashrc!

bastiano wrote:

With #! logo
http://img685.imageshack.us/img685/3456/bashrc.png

Uploaded with ImageShack.us

bastiano can you please post your .bashrc? This is an awesome style

:: AKA xenjii on #crunchbang :: Archlinux.WMFS2 :: EVERYTHING HERE @ Blogger
:: .dotshare :: 1 1 0 1 0 1 0 0 0 ::

Re: Post your .bashrc!

The prompt should be fairly easy. Edit:

    PS1='┌───[\u@\h]──────[\w]\n└───#! '

Or something of that variety. Actually, the #! is a great idea!

And once more: !

Last edited by el_koraco (2011-08-08 14:54:25)

Re: Post your .bashrc!

Here are the relevant ones fro mine

For the prompt

xterm*|rxvt*)
    PS1='\e[1;37m┌───|\e[1;36m\]\u@\h\e[1;37m|────────|\e[1;36m\]\w\e[1;37m|\n└───┤#! '
    ;;
*)
    ;;
esac

Aliases

    alias mocp='mocp -T black_theme'    
alias updateall='sudo apt-get update && sudo apt-get dist-upgrade'
alias in='sudo apt-get install'
alias prg='sudo apt-get purge'
alias upd8='sudo apt-get update'
alias qvr='apt-cache search'
alias plc='apt-cache policy'

Re: Post your .bashrc!

el_koraco wrote:

The prompt should be fairly easy. Edit:

    PS1='┌───[\u@\h]──────[\w]\n└───#! '

Or something of that variety. Actually, the #! is a great idea!

And once more: !

First time I have done a bashrc config usually do GTK, Openbox and conky scripts. I have started on my bashrc and am not doing to bad although how do I add timestamps to everything?

:: AKA xenjii on #crunchbang :: Archlinux.WMFS2 :: EVERYTHING HERE @ Blogger
:: .dotshare :: 1 1 0 1 0 1 0 0 0 ::

110

Re: Post your .bashrc!

what kind of timestamp do you mean, and where?
in the prompt you can put some controll squences to display date and time. Examples:

PS1='current time is \t'
PS1='current time is \T'
PS1='current time \@'
PS1='current time \A'
PS1='current time \D{%F %H:%M:%S}'

the last can use your custom time format to display date and time as you like it.
you can read that in the manpage for bash under "prompting"
the format for \D is explained in "man strftime"

hope this helps
luc

Re: Post your .bashrc!

el_koraco wrote:

The prompt should be fairly easy. Edit:

    PS1='┌───[\u@\h]──────[\w]\n└───#! '

Or something of that variety. Actually, the #! is a great idea!

And once more: !


Yes, it is exactly like that. I'm sorry I didn't post the code.

Re: Post your .bashrc!

@luc

Thanks man. I will be using "PS1='current time is \t'"

I want it to look like:

[usr@host][~] dir
[12.45.53]  documents music downloads
[usr@host][~] cd documents
[usr@host][documents] dir
[12.47.12] text1 text2 text3
[usr@host][~] echo 123
[12.48.04] 123

Understand?

:: AKA xenjii on #crunchbang :: Archlinux.WMFS2 :: EVERYTHING HERE @ Blogger
:: .dotshare :: 1 1 0 1 0 1 0 0 0 ::

Re: Post your .bashrc!

xeNULL wrote:

First time I have done a bashrc config usually do GTK, Openbox and conky scripts. I have started on my bashrc and am not doing to bad although how do I add timestamps to everything?

Don't worry, I know even less than you!

114

Re: Post your .bashrc!

Nothing fancy.

#########
# basic #
#########

# Check for an interactive session #
[ -z "$PS1" ] && return

# bash prompt layout #
PS1='[\u@\h \W]\$ '


#########
# alias #
#########

## ls ##
alias ls='ls --color=auto'
alias lsbin='ls /usr/local/bin/'
alias lslh='ls -lh'

## ncdu ##
alias ncdu='ncdu --exclude /media'

## bashrc info ##
alias bashrcalias='grep alias ~/.bashrc'

## latex ##
alias cleartex="ls -1 | grep -E 'aux|log|dvi|toc' | xargs rm"

## packages ##
#alias pacman='pacman-color'

## cleanup ##
alias rndpix='mv *.{jpg,JPG,gif,GIF,png,PNG,bmp,BMP} ~/Multimedia/Grafik/rndpix/'

## play.py > cplay ##
alias cplay='play.py'

## vnc ##
alias startvnc='sudo rc start x11vnc'
alias stoptvnc='sudo rc stop x11vnc'
alias restartvnc='sudo rc restart x11vnc'

# fortune-mod #
alias bofh='fortune 100% bofh-excuses'

# search AUR #
alias aur='yaourt -Ss'


########
# path #
########

# user bin - use /usr/local/bin/ instead #
#PATH=$PATH:~/bin

#export PATH


#############
# variables #
#############

export VISUAL='/usr/bin/vim'
export PAGER='most'
export GREP_OPTIONS='--color=auto'
export HISTTIMEFORMAT='%F %T '
export HISTSIZE=1000
export EDITOR='vim'

#############
# functions #
############

function dictdeen {
    curl -s dict://dict.org/d:$1:deu-eng | sed 's/^[0-9].*//g'
}

function dictende {
    curl -s dict://dict.org/d:$1:eng-deu | sed 's/^[0-9].*//g'
}

function dictdef {
    curl -s dict://dict.org/d:$1 | sed 's/^[0-9].*//g'
}

######################
# misc before prompt #
######################

cd ~
I'm so meta, even this acronym

Re: Post your .bashrc!

el_koraco wrote:
xeNULL wrote:

First time I have done a bashrc config usually do GTK, Openbox and conky scripts. I have started on my bashrc and am not doing to bad although how do I add timestamps to everything?

Don't worry, I know even less than you!

lol I bet you know things I dont and I know things you dont lol. Thats the best thing about linux, putting minds together we know everything! big_smile

:: AKA xenjii on #crunchbang :: Archlinux.WMFS2 :: EVERYTHING HERE @ Blogger
:: .dotshare :: 1 1 0 1 0 1 0 0 0 ::

116

Re: Post your .bashrc!

Pretty basic as well:

#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

# Aliases
alias ls='ls --color=auto'
alias ipod='ifuse ~/iPod/Mount'
alias uipod='sudo umount ~/iPod/Mount'
alias cpu='cpufreq-info | grep current'
alias temp='acpi -t'
alias autostart='gedit ~/.config/compiz/autostart.sh &'
alias sudo='sudo '
alias pacman='pacman-color'
alias packer='packer-color'
alias conkyrc='gedit ~/.conky/conky &'

# PS1
#PS1='[\u@\h \W]\$ '
PS1='┌─[\u@\h \W]\[\e[0;32m\][${cwd}\t]\[\033[0m\] ${fill}\n\[\033[0m\]└─■ '

# $PATH
PATH=${HOME}/bin:${PATH}

# $EDITOR
export EDITOR="gedit"
Let's do it and don't screw it.
      Github || Deviantart

Re: Post your .bashrc!

@Awebb - Why not just run "alias" instead of using:

alias bashrcalias='grep alias ~/.bashrc'
Note: ** Please read before posting **

BTW if you wish to contact me, send me an e-mail instead of a PM.

118

Re: Post your .bashrc!

@xeNULL
I'm not sure if this will be possible. I do not know of a way to have some lines in the prompt displaying text below the cursor.

@Awebb
why do you use

 alias cleartex="ls -1 | grep -E 'aux|log|dvi|toc' | xargs rm"

insted of

alias cleartex='rm *.{aux,log,div,toc}'

If I am not mistaken your code (the former) will also delete files like "logic_notes.tex" (and it uses pipes).

@all
happy coding (i love this thread)

luc

Re: Post your .bashrc!

here is mine it isn't completely done but its functional smile

http://img827.imageshack.us/img827/3456/bashrc.png

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return


# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+:}ignoredups
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    # We have color support; assume it's compliant with Ecma-48
    # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
    # a case would tend to support setf rather than setaf.)
    color_prompt=yes
    else
    color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\e[1;37m[\t]\e[0;37m [\W]\e[1;37m '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    #alias grep='grep --color=auto'
    #alias fgrep='fgrep --color=auto'
    #alias egrep='egrep --color=auto'
fi

## Dir shortcuts
alias back='cd ..'
alias home='cd ~/'
alias documents='cd ~/documents'
alias downloads='cd ~/downloads'
alias images='cd ~/images'
alias videos='cd ~/videos'
alias bin='cd ~/bin'
alias external='cd /media/XEHD'

## Easier Apt 
alias install='sudo apt-get install'
alias remove='sudo apt-get remove'
alias update='sudo apt-get update'
alias upgrade='sudo apt-get update && sudo apt-get upgrade'
alias dupgrade='sudo apt-get update && sudo apt-get dist-upgrade'
alias orphand='sudo deborphan | xargs sudo apt-get -y remove --purge'
alias cleanup='sudo apt-get autoclean && sudo apt-get autoremove && sudo apt-get clean && sudo apt-get remove && orphand'
alias updatedb='sudo updatedb'
alias ginstall='gksu synaptic'

## Other shortcuts
alias system='~/bin/sysinf'
alias mocp='mocp -T blackwhite'  
alias conkyrc='gedit ~/.conkyrc' 
alias bashrc='gedit ~/.bashrc'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

#----------------------------------------------
# Colors:
#----------------------------------------------
black='\e[0;30m'
blue='\e[0;34m'
green='\e[0;32m'
cyan='\e[0;36m'
red='\e[0;31m'
purple='\e[0;35m'
brown='\e[0;33m'
lightgray='\e[0;37m'
darkgray='\e[1;30m'
lightblue='\e[1;34m'
lightgreen='\e[1;32m'
lightcyan='\e[1;36m'
lightred='\e[1;31m'
lightpurple='\e[1;35m'
yellow='\e[1;33m'
white='\e[1;37m'
nc='\e[0m'
#-----------------------------------------------
# Startup:
#-----------------------------------------------
#!/bin/bash
echo ""
echo "───────────────┐ ░░░░░░░░░░░░░░░░░░░░░░░░░░░"
echo "   | || |_ | | | ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"
echo " |_  __  _|| | └──────────────────────────────┐"
echo -ne "  _| || |_ | |  [$USER@$HOSTNAME] [";date +"%d.%a.%b.%C%y]  |"
echo " |_  __  _||_| ┌──────────────────────────────┘"
echo "   |_||_|  (_) | ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"
echo "───────────────┘ ░░░░░░░░░░░░░░░░░░░░░░░░░░░"

Last edited by xeNULL (2011-08-09 19:33:50)

:: AKA xenjii on #crunchbang :: Archlinux.WMFS2 :: EVERYTHING HERE @ Blogger
:: .dotshare :: 1 1 0 1 0 1 0 0 0 ::

Re: Post your .bashrc!

@xeNULL - you don't need this alias:

alias home='cd ~/'

Just typing "cd" will automatically take you to your home folder.

Note: ** Please read before posting **

BTW if you wish to contact me, send me an e-mail instead of a PM.

Re: Post your .bashrc!

anonymous wrote:

@xeNULL - you don't need this alias:

alias home='cd ~/'

Just typing "cd" will automatically take you to your home folder.

kk big_smile

:: AKA xenjii on #crunchbang :: Archlinux.WMFS2 :: EVERYTHING HERE @ Blogger
:: .dotshare :: 1 1 0 1 0 1 0 0 0 ::

Re: Post your .bashrc!

The notable or interesting ones:

# navigation and human readable sizes
alias ..="cd .."
alias free='echo "Memory free in MiB" && free -m'

# disk free, -T shows us the file system type. Handy.
alias df='df -Th'

# show average cpu usage for a process
alias avg-cpu='ps -o "%cpu" -C $1'

# lock terminal and enter low power suspend mode
# we allow pm-suspend to run without sudo via: 
# https://wiki.archlinux.org/index.php/Pm-utils#User_Permission_Method
alias lock-and-suspend='xscreensaver-command -lock & sleep 5 && (sudo pm-suspend)'

# coffee timer: shows a popup after 4.5 mins
alias coffee='(sleep 270 && zenity --info --title="coffee" --text="Coffee ready\!") &'

# apt aliases (cache calls don't require su) (anyone know how to supply auto-complete for package names?)
alias aptsearch='apt-cache search'
alias aptshow='apt-cache show'

# system update
alias update-distro='sudo apt-get update && sudo apt-get dist-upgrade'

# pipe to clipboard. More handy.
alias clip='xclip -sel clip'

# convert ogg to mp3
alias convert-ogg-to-mp3='for f in *.ogg; do ffmpeg -i "$f" -acodec libmp3lame "${f%%.ogg}.mp3"; done'

p.s. "cd -" is analogous to "undo the previous directory change"

123

Re: Post your .bashrc!

I guess all the people who read this thread do edit their dotfiles (not just ~/.bashrc) quite often when they come to like new features. I do! So I wrote this function (bash/zsh) to edit these files quickly and also source changes (if that makes sense, like with shells but not with vim).

conf () {
  local SOURCE=true
  local FILE=
  local EDITOR=${EDITOR:-${VISUAL:-vi}}
  case "$1" in
    a|alias*)        FILE=.aliases          SOURCE=.;;
    b|bash)          FILE=.bashrc           SOURCE=.;;
    e|env)           FILE=.envrc            SOURCE=.;;
    g|gvim)          FILE=.gvimrc;;
    i|input)         FILE=.inputrc          SOURCE="bind -f";;
    p|private)       FILE=.private_aliases  SOURCE=.;;
    pr|pro|profile)  FILE=.profile          SOURCE=.;;
    v|vi|vim)        FILE=.vimrc;;
    vp|vimpager)     FILE=.vimpagerrc;;
    z|zsh)           FILE=.zshrc            SOURCE=source;;
    ze|zenv|zshenv)  FILE=.zshenv           SOURCE=source;;
    *)               echo "Give an arguemnt." 1>&2; return 2;;
  esac
  $EDITOR $HOME/$FILE
  $SOURCE $HOME/$FILE
}

to edit bashrc type "conf b" edit the file, save and exit and have your changes sourced automatically.
caveat:
do not edit files that should not be sourced in the current shell like this. (e.g don't "conf z" in a bash as you probably do not want ~/.zshrc to be sourced in the current instance of bash)

Happy coding
luc

Re: Post your .bashrc!

luc wrote:

{snip}

    z|zsh)           FILE=.zshrc            SOURCE=source;;

to edit bashrc type "conf b" edit the file, save and exit and have your changes sourced automatically.
caveat:
do not edit files that should not be sourced in the current shell like this. (e.g don't "conf z" in a bash as you probably do not want ~/.zshrc to be sourced in the current instance of bash)

Happy coding
luc

OK, NOOB ALERT!!!!
sourced?  What's that?  I just edit dot files and then save them.  What is this "sourced" thing?

You show:

    z|zsh)           FILE=.zshrc            SOURCE=source;;

then you say: "don't "conf z" in a bash as you probably do not want ~/.zshrc to be sourced in the current instance of bash"

(click) OH!!!!!  You mean don't type "conf z" while editing a bash script, right?

Last edited by Sector11 (2011-10-18 13:01:50)

125

Re: Post your .bashrc!

sourcing is what happens to your ~/.bashrc file when you start an instance of bash (like when you open a terminal or type "bash" with no arguments in any interactive shell)
sourcing a file works like executing a file but with one important difference.
If you execute a file like "./myscript.sh" it will create a new process of bash/sh/dash/zsh (according to the first line of the file) which will read the file and execute all commands in it.
If you are in an interactive shell session (like a terminal) you can "source" files. then your interactive instance of the shell (no new process) will read the file and execute the commands found in it.

to understand the difference you can do this in a terminal (running bash):

cat > my_test_file << EOF
#!/bin/bash
ps
some_variable=new
echo in file: \$some_variable
EOF
chmod +x my_test_file
ps
some_variable=old
echo "now it is: $some_variable"
./my_test_file
echo "now it is: $some_variable"
echo ""
echo "this is equivalent to this (only the argv[0] is different)"
bash my_test_file
echo "now it is: $some_variable"
echo ""
echo "this is different"
. my_test_file
echo now it is: $some_variable
help .

links:
http://en.wikipedia.org/wiki/Shebang_(Unix)
http://www.google.de/search?q=source+a+file

Last edited by luc (2011-10-18 13:40:32)