I have a korn util script that isn't receiving correct parameters. I'm not sure why. I'm new to korn, and searching for the issue online didn't help.
I execute the calling script this way from calling dir: ksh test_k.ksh
test_k.ksh:
#!/bin/ksh
# Invoke the initialization script
[[ ! -r /home/mcleary/k_test/bin/init.ksh ]] \
&& print -u2 "$0: /home/mcleary/k_test/bin/init.ksh not found" && exit
. /home/mcleary/k_test/bin/init.ksh
#I had to add -fDEV_OVR below for executing in dev env, but this is source of params and I see the resemblance to the garbage here
m_F -fDEV_OVR -t'echo "No skipping"' MMMM <<!
cd ${REMOTE_DIR}
! #command called here, calls utils.michele.ksh
init.ksh looks like this (moved it to my dir to add #!/bin/ksh at the top):
init.ksh:
#!/bin/ksh
# Set up environment
umask 002
# Check $M_HOME
if [[ -z "$M_HOME" ]]; then
print "\$M_HOME is not set"
echo "setting M_HOME different way then echo"
M_HOME="/appl/"
echo $M_HOME
echo "export and echo again next"
export M_HOME="/appl/"
echo $M_HOME
fi
echo "m_home:" $M_HOME
# Read $M_HOME/etc/m.env
if [[ -r ${M_HOME}/etc/m.env ]]; then
. ${M_HOME}/etc/m.env
echo "first case home etc m.env found"
...
# Read $M_HOME/bin/utils.ksh
if [[ -r /home/mcleary/k_test/bin/utils.michele.ksh ]]; then
. /home/mcleary/k_test/bin/utils.michele.ksh
echo "michele utils found" #it prints this
else
if [[ -f /home/mcleary/k_test/bin/utils.michele.ksh ]]; then
print "\/home/mcleary/k_test/bin/utils.michele.ksh not readable, exiting"
echo "michele utils not readable"
else
print "\/home/mcleary/k_test/bin/utils.michele.ksh not found, exiting"
echo "michele utils not found"
fi
exit
fi
So what happens in the init file is that it doesn't know what M_HOME is so it defaults to what I give it. It then finds $M_HOME/etc/m.env, but print garbage, shown below. There aren't any error messages otherwise. Why are the params not working?
The env file doesn't have #!/bin/ksh at the top, and has a list of exports. M.env:
export GROOVY_dir=${M_HOME}/dsa5/oraclev6/groovy
etc
utils.michele.ksh:
#!/bin/ksh #I added this, former version did not have it
...
function m_F {
when getopts f:t: opt; do
case $opt in
f) ARGVAL="OPTARG"; shift;;
t) DEVCMD="OPTARG"; shift;;
?) ;;
esac
done
M_SITE_NAME="$1"
echo "M_HOME:" $M_HOME #looks good
echo "M_SITE_NAME:" $M_SITE_NAME #problem..gives garbage: -techo "No skipping"
# Set site, ID
M_F_SITE=$(eval echo \$${M_SITE_NAME}_FSITE) #gets from env var, but not filling
[[ -z "$M_F_SITE" ]] && m_Log "m_F: \$M_F_SITE not found" && m_exit
echo "M_F_SITE here: $M_F_SITE" #problem..gives garbage...hBtecho No skipping_FSITE
... elif [[ "ARGVAL" == "DEV_OVR" ]]; then ...
m_Ffunction three arguments,-fDEV_OVR-t'echo "No skipping"', andMMMM. The function uses the first of these to initializeM_SITE_NAME. It is unclear what you are expecting should happen.getoptsthat will assign the literal stringsOPTARGto the variablesARGVALandDEVCMDif the optionsfandtare used. It would be better to show the actual code you are using rather than rewriting your scripts for this question. You also appear to be missingshift "$(( OPTIND - 1 ))"after that new loop that you inserted, but I have no way of telling what your actual code looks like (because this is certainly not your actual code).