【发布时间】:2018-09-20 04:56:41
【问题描述】:
在独立的 ConTeXt 中,文件 tex/setuptex 包含需要当前路径 tex/setuptex 的代码(通常是例如 $HOME/context、/opt/context 等)。代码如下所示:
# this resolves to path of the setuptex script
# We use $0 for determine the path to the script, except for:
# * bash where $0 always is bash; here we use BASH_SOURCE
# * ksh93 where we use ${.sh.file}
# Thanks to Vasile Gaburici and Alessandro Perucchi for reporting this
# * http://www.ntg.nl/pipermail/ntg-context/2008/033953.html
# * http://www.ntg.nl/pipermail/ntg-context/2012/068658.html
if [ z"$BASH_SOURCE" != z ]; then
SCRIPTPATH="$BASH_SOURCE"
elif [ z"$KSH_VERSION" != z ]; then
SCRIPTPATH="${.sh.file}"
else
SCRIPTPATH="$0"
fi
通常使用运行 ConTeXt 所需的各种环境变量来更新当前环境,. path/tex/setuptex。
在 BusyBox(例如 Alpine Linux)中,$SCRIPTPATH 是 /,而且获取路径的正确方法是什么并不明显。将此行添加到脚本中:
echo "SCRIPTPATH $0 : $1 : $2"
产量:
SCRIPTPATH sh : :
env 与 setuptex 类似,不会产生任何结果。
所以我不确定从哪里开始。
如何复制通常用于获取当前执行脚本路径的*sh 功能?
【问题讨论】:
-
问题是您正在获取文件 (
. /path/to/context) 而不是运行它 (sh /path/to/context)。我没有适合您的解决方案,但您可以考虑解决方法,例如:. /path/to/context /path/to/context将在$1中存储答案(可能相对于$PWD) -
感谢@AdamKatz;使用
.采购是在 ConTeXt 的说明中,很多人都会熟悉。 -
是的,我假设您需要
.或source,因为导入了一些环境、函数和/或别名的组合,而您无法通过新的shell 引入这些组合。这就是为什么我能提供的只是那种尴尬的解决方法。这可能是一个busybox错误。