Shell script to validate shell type

korn bash shellSometimes its required to check the shell type to dynamically carry out some operation in unix environement.Here is a small shell script I wrote to check shell type.Currently the script only checks for Korn and bash shell type.
Script can be modified according to need.This script is validated on AIX,RHEL,OEL and HP-UX.

# Validation to check shell
echo “$SHELL” | grep -q “ksh”
if [[ $? -eq 0 ]] ; then
echo
echo K Shell found
echo
exit
fi

echo “$SHELL” | grep -q “bash”
if [[ $? -eq 0 ]] ; then
echo
echo Bash Shell found
echo
exit
fi
# validation end here

1)In the script given above we are doing grep on $SHELL variable to search “ksh” and “bash”.

2)In $? -eq 0$? is the return code for the command that was executed previously and -eq stands for equals.

For successful completion the standard return code is 0.

Leave a Reply