[comp.unix.wizards] Csh "source" for Ksh and other neat functions

jep@fantasci.UUCP (Joseph E Poplawski) (12/05/88)

For the person who wanted the Csh "source" function for Ksh, here it is.  Also
included are the functions "null", which allows you to zero out the list of 
files named, "chmog" which allows you to change the mode, owner, and group of
a file at the same time, and "setenv" which is basically the same as the Csh
function of the same name.

source() {
	if [ $# -eq 0 ]
	then
		echo ""; echo "Usage: source file1 file2 ..."; echo ""
		return 1  
	else
		for file
		do
			if [ ! -f "$file" ]
			then
				echo ""
				echo "source: $file doesn't exist!"
				echo ""
				continue
			fi
			. $file
		done
	fi
}

chmog() {
	if [ $# != 4 ]
	then
		echo ""; echo "Usage: chmog [mode] [owner] [group] file"
		echo ""
		return 1  
	else
		chmod $1 $4
		chown $2 $4
		chgrp $3 $4
	fi
}

null() {
	if [ $# -eq 0 ]
	then
		echo ""; echo "Usage: null file1 file2 ..."; echo ""
		return 1  
	else
		for file
		do
			if [ ! -s "$file" ]
			then
				echo ""
				echo "null: $file doesn't exist or empty!"
				echo ""
				continue
			fi
			cat /dev/null >$file >>/dev/null 2>&1
		done
	fi
}

setenv() {
	if [ $# -ne 2 ]
	then
		echo "setenv: too few args"
	else
		eval $1=$2
		eval export $1
	fi
}

Enjoy...  And if you improve these in any way, let me know so I can improve
mine at the same time!

-Jo
-------------------------------------------------------------------------------
|  Joseph E Poplawski  (Jo)                   US Mail:  1621 Jackson Street   |
|                                                       Cinnaminson NJ 08077  |
|  UUCP:..!rutgers!rochester!moscom!telesci!fantasci!jep                      |
|       ..!princeton!telesci!fantasci!jep                                     |
|       ..!pyrnj!telesci!fantasci!jep           Phone:  +1 609 786-8099 home  |
-------------------------------------------------------------------------------
|                     He who dies with the most toys wins!                    |
-------------------------------------------------------------------------------
|         Copyright (C) 1988  Joseph E Poplawski  All rights reserved.        |
-------------------------------------------------------------------------------