Alter Your Environment with Functions

by mike on July 9, 2011

Environmental Functions
You can use functions to alter the environment of the user.  These functions can be added into the .bash_profile of an individual user or in the system wide /etc/profile.  It is best to verify the functions have no detrimental impact by using a normal user first as a test base.  You will need to enter the functions in the .bash_profile in the following format.  In this example two functions have been used and can be called with “dfh” or “duh”.

dfh ()
df -h
duh ()
du -kh * | awk '{print $2,$1}' | sort -n | tr ' ' "\t"

Once the .bash_profile has been edited and saved then you can either login and log back in, or source the file.
source .bash_profile

Now the functions should work.


Carl Lowenstein July 10, 2011 at 3:20 am

du -kh * | awk ‘{print $2,$1}’ | sort -n | tr ‘ ‘ “\t”

Why go to the bother of using tr to change spaces to tabs. Awk can do it for you.
What is the intent of the numeric “-n” flag to sort? It does not seem to do anything useful.

du -kh * | awk ‘{print $2,”\n”,$1}’ | sort

PePa July 10, 2011 at 1:57 pm

It’s probably better to declare aliases if you can rather than functions. I use functions when there are arguments that can’t be put at the end, like:

rotatevideoright () {
mencoder -ovc lavc -vf rotate=1 -oac copy ${1} -o ${1}.avi

Comments on this entry are closed.

Previous post:

Next post: