Skip to content

Instantly share code, notes, and snippets.

@kunalkumar
Created September 22, 2010 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunalkumar/6b3442d3c6875ece69f9 to your computer and use it in GitHub Desktop.
Save kunalkumar/6b3442d3c6875ece69f9 to your computer and use it in GitHub Desktop.
Shell Script to Manage Environment Configuration at login
#! /bin/ksh
export ENV_FILE_LOC=/home/kunalkumar/env
prepareMenu(){
unset fileName
unset menuString
set -a fileName
set -a menuString
index=0;
for file in `ls $ENV_FILE_LOC`
do
string=`grep "DISPLAY_MENU_STRING" $ENV_FILE_LOC/$file | awk -F"=" '{ print $2 }'`
if [[ $string != "" ]]; then
fileName[index]=$file;
menuString[index]=$string;
index=`expr $index + 1 `;
fi
done
}
displayMenu(){
echo "Available Shell Configuration. ";
index=1;
totalMenuItem=${#fileName[*]};
while [[ $index < $totalMenuItem ]]; do
echo "$index - ${menuString[$index]}";
index=`expr $index + 1`
done;
echo "Please select configuration : ";
}
readValues(){
read inputOptions;
}
executeOptions(){
OLDIFS=$IFS;
export IFS=" ";
inputArray=$inputOptions;
totalInputOptions=${#inputArray[*]};
echo "Sourcing Default Environment...";
. $ENV_FILE_LOC/1_Default
if [[ $totalInputOptions -eq 0 ]]; then
echo "No option selected!";
return;
fi
index=0;
while [[ $index < $totalInputOptions ]]; do
echo "Sourcing environment from ${fileName[ ${inputArray[$index]} ]}";
. $ENV_FILE_LOC/${fileName[${inputArray[$index]}]};
index=`expr $index + 1`;
done
export IFS=$OLDIFS
}
prepareMenu
displayMenu
readValues
executeOptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment