ifs.sh 821 Bytes
Newer Older
Eric Coissac committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#
# LECA Bash library
#
# The LECA bash library provides a set of function used for helping
# development of bash script mainly to write job script on the luke
# cluster
#
# The files from the LECA Bash library must be sourced from your main script
#

include stack

newstack LECABASH_IFS_STACK

function pushifs() {
	if [[ -z "${IFS}" ]]; then
		pushvalue LECABASH_IFS_STACK "@@NULL@@"
	else
		local v=$(echo -n "$IFS" | od -b | head -n +1 | sed 's/[0-9]* //' | sed 's/ /\\/g' | sed 's/^/\\/')
		pushvalue LECABASH_IFS_STACK "$v"
	fi
	
	if [[ -z "$1" ]]; then
		unset IFS
	else
		IFS="${1}"
	fi

}

function popifs() {

	local v
	v=$(popvalue LECABASH_IFS_STACK v)
	
	if [[ "$?"!="0" ]]; then
		if [[ "$v"=="@@NULL@@" ]]; then
			unset IFS
		else
			IFS=$(eval "echo -n \$'$x'")
		fi
	else
		return 1
	fi
	
	return 0
	
}