【问题标题】:bash script command not found - command correctly implemented未找到 bash 脚本命令 - 命令已正确执行
【发布时间】:2013-10-18 06:28:15
【问题描述】:

我写了一个 bash 脚本,我收到了这些消息:

/home/myname/documents/myscripts/run_tearingmode.sh:第 44 行:mpirun2:找不到命令:

这里是脚本的相关部分

if [[ "$run_jobs" == "y" ]]
 then
 printf "The jobs run one after the other. Have fun with the analysis. \n "
 for ((i=1;i<=$number_subfolders;i++))
  do
  sub_folder=${main_folder}_$i
  cd
  cd gkw/run/${main_folder}/$sub_folder #change into certain subfold
  pwd
  mpirun2 -np 8 ./gkw_btppx-gnu-DP_3481.x  #run on all 8 frames #line 44 Here is the problem 
  cd
 done
fi

我的问题是,当我在某个文件夹中输入该行作为命令时,程序运行正常。这向我表明我正确地实现了它。使用 pwd 我也知道我在正确的文件夹中。 我没有发现我在哪里犯了错误。我需要在脚本中使用某个括号或等效的东西来运行程序吗? 我还删除了命令前面的空白,但没有任何改变。 有什么问题/遗漏了什么?

编辑:问题是,您不能在这样的脚本中从 bashrc 运行别名。 所以我补充说:

mpirun2='/Path/to/mpirun'

到我的脚本并将脚本中的命令更改为:

"$mpirun2" -np 8 ./gkw_btppx-gnu-DP_3481.x  #run on all 8 frames

这行得通。 非常感谢。 (不幸的是,我自己不能作为初学者写这个答案:))

【问题讨论】:

  • 在脚本运行时检查PATH 环境变量的值(即echo $PATH)。指定mpirun2 的完整路径应该会有所帮助。

标签: linux bash shell command


【解决方案1】:

如果 mpirun2 不在用户的 PATH 上('which -a' 将不返回任何内容)。您必须使用完整路径调用它:

/full/path/to/mpirun2 -np 8 ./gkw_btppx-gnu-DP_3481.x

【讨论】:

    【解决方案2】:

    我想如果你在脚本顶部添加一个 shebang

    #/usr/bin/env bash
    

    以及可执行文件的完整路径(此命令显示它which mpirun2)应该可以工作。

    【讨论】:

    • 我的脚本开头确实有 #!/bin/bash。在我想启动程序之前,我的脚本运行良好。我还在 bashcr alias mpirun2='/home/myname/mpich2/bin/mpirun' 中将 mpirun2 命名为别名。该文件夹的实际路径是什么?
    • 您的别名在您的脚本中不可用。而不是别名,将其添加到您的 .profile.bash_profile(不是 .bashrc):PATH="/home/myname/mpich2/bin/mpirun:$PATH"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2020-05-12
    • 2017-01-04
    相关资源
    最近更新 更多