-
-
Save kunalkumar/6b3442d3c6875ece69f9 to your computer and use it in GitHub Desktop.
Shell Script to Manage Environment Configuration at login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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