【问题标题】:symlink script does not exist on startxstartx 上不存在符号链接脚本
【发布时间】:2021-10-31 09:52:41
【问题描述】:

我遇到的问题是在脚本中运行一个名为 example 的符号链接(示例指向 b.sh)。 从终端运行 $ example 会将消息 scriptB was found 附加到日志中。如果我从$HOME 运行$ ./b.sh,也会发生同样的情况。但是,example 在启动 X 时不会执行。 我在我的系统上创建了以下最小设置来模仿我的问题。

a.sh

#!/bin/bash
type example ||
    echo "error: example could not be found." >>"$HOME/example.log"
~/b.sh

b.sh

#!/bin/bash
echo "scriptB was found" >>"$HOME/example.log"

.xinitrc

#!/bin/sh
if [ -x "$HOME/a.sh" ]; then
    bash ~/a.sh
fi

最小设置

  • X 执行a.sh
  • 使用$ ln -s ~/a.sh ~/.local/bin/example 创建的链接
  • 使用$ chmod u+x a.sh b.sh 使脚本可执行并使用ls -l 验证可执行
  • .bashrc 中将$HOME/.local/bin 附加到我的PATH 环境变量中

重启X(或重启)后的日志是:

error: example could not be found.
scriptB was found

【问题讨论】:

  • >/dev/null 只重定向标准输出,不重定向标准错误。
  • @CharlesDuffy 我只是在那里让 a.sh 保持沉默。使用 &> 重定向或没有重定向的示例似乎仍然不存在。
  • appended $HOME/.local/bin to my PATH environment variable 究竟在哪里以及如何?不在.xinitrc
  • @KamilCuk 在我的.bashrc 我有PATH="$PATH:$HOME/.local/bin"
  • in my .bashrc 所以它在.bashrc。您的脚本不使用.bashrc。脚本中的导出路径。请注意,您有#!/bin/bash,但您使用. ~/a.sh,所以它使用sh,而不是bash(无论如何都不使用.bashrc)。这是一些非常奇怪的bash -c '. ~/b.sh',只需运行脚本bash ~/b.sh,在子shell 中进行采购没有意义。

标签: bash path x11


【解决方案1】:
.... ~/.local/bin/example

所以将该路径添加到PATH

#!/bin/sh
export PATH="$HOME/.local/bin:$PATH"
example

【讨论】:

  • .xinitrc 中将$HOME/.local/bin 附加到我的PATH 解决了我的问题
猜你喜欢
  • 2018-11-06
  • 2012-01-10
  • 2017-07-24
  • 1970-01-01
  • 2016-04-07
  • 1970-01-01
  • 2012-03-20
  • 2013-02-17
  • 1970-01-01
相关资源
最近更新 更多