【问题标题】:How to run a bash script via absolute path? [closed]如何通过绝对路径运行 bash 脚本? [关闭]
【发布时间】:2016-08-12 22:33:28
【问题描述】:

我已经在这里发布了这个问题:

https://superuser.com/questions/1067609/how-to-run-a-bash-script-via-absolute-path

但我希望如果我在这里复制它,我会尽快得到答案:)

我有一个文件:

/Users/danylo.volokh/test/test_bash_script.sh

内容很简单:

#!/usr/bin/env bash
echo "-- print from script"

我在文件夹“danylo.volokh”中

此命令运行良好:

Danilos-MacBook-Pro:~ danylo.volokh$ test/test_bash_script.sh 
-- print from script

但如果我尝试使用绝对路径运行,我会收到错误:

Danilos-MacBook-Pro:~ danylo.volokh$ /test/test_bash_script.sh 
-bash: /test/test_bash_script.sh: No such file or directory

我想从任何文件夹中运行一个带有绝对路径的命令并获取要执行的脚本。

【问题讨论】:

  • 你应该修正你对绝对路径的理解,绝对路径是/Users/danylo.volokh/test/test_bash_script.sh而不是/test/test_bash_script.sh
  • 请不要交叉发帖。我可以向你保证,这只会激怒人们,而不是“尽快得到你的答案”; SuperUser 完全适合您的问题。此外,当您在此处发布时,您在 SU 的问题已有两个答案
  • 感谢您的好建议。其实我已经得到了答案。
  • 我投票结束这个问题作为题外话,因为它是superuser.com/questions/1067609/… 的副本实际上我已经得到-2 来复制这个。我可以以某种方式修复它吗?
  • 你可以简单地删除这个问题。 (但请注意,反复删除您自己的问题会对您的声誉产生负面影响。)

标签: linux macos bash shell bash-completion


【解决方案1】:

/test/test_bash_script.sh 从根目录查找文件!您的路径应该来自根目录,而不是来自当前目录。

试试/Users/danylo.volokh/test/test_bash_script.sh

【讨论】:

    【解决方案2】:

    您的路径不正确。你应该运行:

    /Users/danylo.volokh/test/test_bash_script.sh
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-04
      • 2019-04-02
      • 2016-01-09
      • 1970-01-01
      • 2019-07-18
      • 2016-10-01
      • 2011-04-04
      相关资源
      最近更新 更多