korn 脚本为发送到 utils 文件中函数的参数打印垃圾

korn 脚本为发送到 utils 文件中函数的参数打印垃圾

我有一个 korn util 脚本未接收正确的参数。我不知道为什么。我是 korn 的新手,在线搜索该问题没有帮助。

我通过调用 dir: ksh test_k.ksh 以这种方式执行调用脚本

测试_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):

初始化.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

因此,init 文件中发生的情况是,它不知道 M_HOME 是什么,因此它默认为我给它的内容。然后它找到 $M_HOME/etc/m.env,但打印垃圾,如下所示。否则没有任何错误消息。为什么参数不起作用?

env 文件顶部没有 #!/bin/ksh,但有一个导出列表。 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" ]];然后 ...

相关内容