regex and variable

didbaba didbaba at free.fr
Tue Jun 19 10:50:22 PDT 2001


I try to write a little fonction to add a path $chemin to PATH only if $chemin is not all ready on PATH.

Here is my first founction but, too long and very badly written 

add_path()
{	
	sentier=$1
	echo $PATH | egrep ^${sentier} &> /dev/null
	DEBUT=$?
	echo $PATH | egrep :${sentier} &> /dev/null
	MILIEU=$?
	if [ $DEBUT = $MILIEU ] ;
		then 
		PATH=$PATH:$sentier
	fi
}

Here is my second attempt, but I don't succeed.
I do not know why ? Maybe a new eye could find my mistake, or could propose somethin more easy


# usage : add_path /chemin
add_path()
{
sentier=$1
	if [ "`echo $PATH | egrep (^|:)${sentier} &> /dev/null`" != "0" ];
	then PATH=$PATH:$sentier 
	fi
}


thx in advance

-- 
didbaba
powered by LinuxFromScratch 2.4
-- 
Unsubscribe: send email to lfs-apps-request at linuxfromscratch.org
and put unsubscribe in the subject header of the message



More information about the blfs-support mailing list