0

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 ...

4
  • You are giving your m_F function three arguments, -fDEV_OVR -t'echo "No skipping"', and MMMM. The function uses the first of these to initialize M_SITE_NAME. It is unclear what you are expecting should happen. Commented Sep 16, 2021 at 13:50
  • M_SITE_NAME should be MMMM parameter, so eval echo should give MMMM_FSITE to pick that up from the env file. Plus the utils script requires DEVCMD="$OPTARG"; shift;; -fDEV_OVR passed as an arg to run in dev environment. So that's why I added it as a param in m_F call. utils script does this: elif [[ "$ARGVAL" == "DEV_OVR" ]]; then ... Commented Sep 16, 2021 at 14:10
  • I'm not sure why the original had -t for the echo part, but doesn't seem to do anything with it. I had looked up -t, but the definition didn't make sense with this use. Plus comments say we need -fDEV_OVR, but the code looks for "DEV_OVR". The -f flag didn't make sense when I looked it up either. Commented Sep 16, 2021 at 14:46
  • You've just updated your code adding a loop over getopts that will assign the literal strings OPTARG to the variables ARGVAL and DEVCMD if the options f and t are 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 missing shift "$(( 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). Commented Sep 16, 2021 at 14:46

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.