Shell environment variables allow you to easily access commonly used filenames/strings without the hassle of typing them out in longhand.
For example instead of typing out:
CODE:
cd /usr/local/etc/rc.d
it's a lot quicker just typing:
CODE:
cd $rc_dir
Even better, command line completion in CSH allows you to use
autocomplete on env variables, so you only need to type the first few chars of the variable, hit and have a list of possible completions given:
CODE:
[1:36:07] munk@users /home/munk# cd $r<TAB>
rc_dir rcconf rejectlog rubybase
giving all the env variables that start with 'r'.
Adding env variables can be done on the commandline using:
CODE:
setenv var_name string
where 'var_name' is the name of the variable you want to create and 'string' is the string you want to assign to the vbl.
However the best way is to add 'setenv' lines to your ~/.cshrc file so the variables are ready to use when you login:
CODE:
; grep setenv $cshrc | head
setenv munk_dir "/home/munk/"
setenv PAGER "less -i"
setenv EDITOR vim
setenv PAGER "less -i"
setenv BLOCKSIZE K
setenv MAIL /var/mail/$USER
setenv TERM xterm-color
# Common setenvs:
setenv tmp /home/munk/tmp/tmp.$$
setenv MONTH `date "+%m"`
Some of my fav env vbls:
CODE:
# useful for redirecting output to a temp file unique to this login session - 'grep something somedir -ri > $tmp':
setenv tmp /home/munk/tmp/tmp.$$
# useful for creating timestamps in filenames - tar zcvf sometar.$DATE.tar.gz somedir:
setenv DATE `date "+%Ymd"`
# easy access to /var/log/messages - 'tail -f $messages' etc:
setenv messages /var/log/messages
# start/stop/restart system daemons quicker with '$rc_dir/daemon.sh restart':
setenv rc_dir /usr/local/etc/rc.d
# access the perl base directory quicker:
setenv perlbase /usr/local/lib/perl5/site_perl/5.8.8
# crontab:
setenv crontab /etc/crontab
# quickly edit ~/.cshrc - vi $cshrc:
setenv cshrc /home/munk/.cshrc
# change the order of sourceforge websites that portupgrade fetches from by default:
setenv MASTER_SITE_SOURCEFORGE \
"http://eu.dl.sourceforge.net/%SUBDIR%/ \
http://us.dl.sourceforge.net/%SUBDIR%/ \
ftp://us.dl.sourceforge.net/pub/sourceforge/%SUBDIR%/ \
ftp://ftp.kddlabs.co.jp/sourceforge/%SUBDIR%/ \
ftp://ftp.chg.ru/pub/sourceforge/%SUBDIR%/"
Any time I find myself using a string on the commandline more than half a dozen times in a session I usually add a variable in $cshrc for it - actually using a shell alias 'cshrc_edit', but that's another top tip and needs an article all to itself :)
Just got through reading an interesting article on how to review your most commonly used Unix commands. The idea is to sort the most commonly used commands numerically with a view to maybe shortening the most command ones using aliases, similar in a way
Tracked: Oct 10, 01:37