首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行shell脚本时出现“命令未找到”错误

运行shell脚本时出现“命令未找到”错误
EN

Unix & Linux用户
提问于 2019-01-23 16:31:40
回答 1查看 443关注 0票数 -2
代码语言:javascript
复制
#!/bin/bash
# pre.sh revision 4.0.0  Date: 2011/12/24

### Path ###
FASTAR_DIR=$(cd $(dirname $0);pwd)

##### Function s #####
. ${FASTAR_DIR}/"script.func"

usage(){
  echo "Usage: " $COMNAME " [option]"
  echo "  option   :  ...... by 1 process"
  echo "             -n  ... batch process by  process"
  echo "             -all ........ batch process"
  echo "             -e .......... use exact wall distance mode"
  echo "             -metis ...... use pre-fastar metis version"
  echo "             -fsi ........ use pre-fastar metis version with FSI mode"
  echo "             -emetis ..... use pre-fastar metis version with exact wd mode"
  echo "             -efsi ....... use pre-fastar metis version with FSI and exact wd mode"
  echo "             -h .......... show this statement"
}

##### Function e #####

#======================================#
# Main                                 #
#======================================#
#=== initialize ===#
COMNAME=`basename $0`
set_variables
if [ $# -eq 1 ]; then
  case $1 in
    "-all" | "-e" | "-metis" | "-fsi" | "-emetis" | "-efsi") opt=$1      ;;
                                                       "-h") usage; exit ;;
                                                          *) usage; exit ;;
  esac
  cpu=1
elif [ $# -eq 2 ]; then
  case $1 in
    "-n") opt=$1      ;;
       *) usage; exit ;;
  esac
  if [ $2 -ge 1 ]; then
    cpu=$2
  else
    cpu=1
  fi
elif [ $# -gt 2 ]; then
  usage; exit
else
  opt="hoge"
  cpu=1
fi

#=== read inputfile ===#
read_input
case $reorder in
  ".true." | ".TRUE." | "T" | "t")
    reorder_check="TRUE"
    ;;
                                *)
    reorder_check="FALSE"
    ;;
esac

#=== ABORT ===#
trap 'abort 1 $COMNAME' 1 2 3 9 15

#=== Make directories ===#
make_dir

#=== preprocess ===#
if test $opt = "-all" ;then
  echo $NPREFAST...
  rm -f $TMP_FILE
  if [ $domain -ge 2 ]; then
    n_loop=$domain
    id=1
    for ((id=1; id<=$n_loop; id++))
    do
      echo "$NPREFAST $id  > $TMP_FILE$id &"
      $PREFAST $id  > $TMP_FILE$id &
    done
    wait

    i=1
    for ((i=1; i<=$domain; i++))
    do
      cat $TMP_FILE$i >> $TMP_FILE
      rm -f $TMP_FILE$i
    done

  elif [ $domain -eq 1 ]; then
    $PREFAST
    echo ""
  else
    echo "ERROR: It is wrong that total number of domain in $INPUT."
    exit
  fi

elif test $opt = "-n"; then
  echo $NPREFAST...
  rm -f $TMP_FILE
  n_loop=`expr $domain / $cpu`
  id=1
  i=1
  for ((i=1; i<=$n_loop; i++))
  do
    var=`expr $cpu \* \( $i - 1 \) + 1`

    id=$var
    j=1
    for ((j=1; j<=$cpu; j++))
    do
      echo "$NPREFAST $id  > $TMP_FILE$id &"
      $PREFAST $id  > $TMP_FILE$id &
      id=`expr $id + 1`
    done
    wait
  done

  if [ `expr $id - 1` -lt $domain ]; then
    while [ $id -le $domain ];
    do
      echo "$NPREFAST $id  > $TMP_FILE$id &"
      $PREFAST $id  > $TMP_FILE$id &
      id=`expr $id + 1`
    done
    wait
  fi

  i=1
  for ((i=1; i<=$domain; i++))
  do
    cat $TMP_FILE$i >> $TMP_FILE
    rm -f $TMP_FILE$i
  done

elif test $opt = "-e" ;then
  echo $NPREFAST...
  rm -f $TMP_FILE
  $PREFAST -e

elif test $opt = "-metis" ;then
  echo $NPREMETIS...
  rm -f $TMP_FILE
  $PREMETIS

elif test $opt = "-fsi" ;then
  make_dir_fsi
  echo $NPREMETIS...
  rm -f $TMP_FILE
  $PREMETIS FSI

elif test $opt = "-emetis" ;then
  echo $NPREMETIS...
  rm -f $TMP_FILE
  $PREMETIS -e

elif test $opt = "-efsi" ;then
  make_dir_fsi
  echo $NPREMETIS...
  rm -f $TMP_FILE
  $PREMETIS -eFSI

else
  echo $NPREFAST...
  rm -f $TMP_FILE
  $PREFAST
fi

#=== reorder ===#
case $reorder_check in
  "TRUE")
    echo $NREORDGRID...
    $REORDGRID
    echo $NREORDINDX...
    $REORDINDX
    ;;
esac

exit

我尝试运行一个shell脚本,但出现了以下错误:

$ pre.sh

/home/gakubu/FaSTAR2019/Bridget2019/Kenkyuu/pre.sh:第8行: /home/gakubu/FaSTAR2019/Bridget2019/Kenkyuu/script.func:没有这样的文件或目录/home/gakubu/FaSTAR2019/Bridget2019/Kenkyuu/pre.sh:第30行: set_variables:命令未找到/home/gakubu/FaSTAR2019/Bridget2019/Kenkyuu/pre.sh:行: read_input:命令未找到/home/gakubu/FaSTAR2019/Bridget2019/Kenkyuu/pre.sh:行: make_dir:命令未找到

..。

$

代码语言:javascript
复制
enter code here

这意味着什么,我该如何解决这个问题?

EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2019-01-23 16:56:59

该脚本在第8行中有以下代码:

代码语言:javascript
复制
. ${FASTAR_DIR}/"script.func"

这会导致一个文件,一个特定的目录。该文件可能包含shell函数定义。根据错误消息,文件是找不到的,没有找到这个文件的效果是它定义的函数后来没有找到(这些是您得到的“命令未找到”错误)。

假定文件script.func与脚本本身位于同一个目录中。如果您已经将脚本移到了它当前所在的位置,但忘记了用它移动script.func文件,那么这就是错误的原因。

我不打算对脚本本身做进一步的评论,只是说它使用了未引用的变量展开,使得它变得非常脆弱,而且可能不安全。

票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/496257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档