【问题标题】:Custom commands path error in bashbash中的自定义命令路径错误
【发布时间】:2016-09-13 22:51:21
【问题描述】:

我尝试在 ubuntu 12.04 中创建一些 bash 自定义命令,所以我使用 mkdir bin 在我的主目录中创建了一个个人 bin,并使用 nano test 添加文件并将此 bash 脚本放入:

#!/bash/bin echo "totally works"

然后是chmod 775 test

所以这就是问题所在,每当我执行test 时,都没有错误,也没有输出。但是当我执行./test 时,它会返回totally works。我查了.profile,脚本说:

# set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi

请不要说我没有退出并重新登录,因为我做到了。而且,同样的事情,当我执行test 时,没有错误也没有输出。

我还尝试使用echo $PATH 检查$PATH,我得到了这个:

/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

所以我被这个难住了,谢谢你的任何帮助。

【问题讨论】:

  • 别叫它test。已经有一个名为test 的命令。将您编写的脚本移动到新创建的bin 目录中。您可以一步完成:mv test ~/bin/another_name
  • 正如埃里克所说,不要称它为test。此外,要验证您的 bin 目录是否在您认为的位置,请运行 ls "$HOME/bin"
  • 好的,我试过ls $HOME/bin,它说test,然后我将test重命名为test5,然后重命名为pooperdooper,结果相同:bash: pooperdooper: command not found和@987654346 @
  • 好的,在这种情况下,~/.profile应该$HOME/bin放入PATH。试试source ~/.profile; echo "$PATH" 看看它是否被添加到路径中。如果没有,那么在初始化过程中的某个地方,PATH 似乎会被其他语句覆盖。
  • 成功了!谢谢约翰!

标签: linux bash shell ubuntu command-line


【解决方案1】:

你的 hashbang 行不正确

#!/bin/bash

#!/usr/bin/env bash

【讨论】:

  • 好的和正确的观点。但是,如果这是问题所在,则 OP 看到的错误消息应包含有关 bad interpreter 的内容。
猜你喜欢
  • 2017-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多