我有 debian 挤压 amd64。我当前的外壳是 bash。如果我在终端中编写以下内容,它会起作用:
$ uname -a
Linux core 2.6.32-5-amd64 #1 SMP Fri May 10 08:43:19 UTC 2013 x86_64 GNU/Linux
$ echo $SHELL
/bin/bash
$ echo $(realpath test.sh)
/home/ffortier/test.sh
Run Code Online (Sandbox Code Playgroud)
我的 test.sh 文件如下所示:
#!/bin/bash
echo $(realpath "$1")
Run Code Online (Sandbox Code Playgroud)
如果我尝试执行以下操作,则会出现错误
$ ./test.sh test.sh
./test.sh: line 2: realpath: command not found
Run Code Online (Sandbox Code Playgroud)
如何在 bash 文件中使用 realpath 命令?
附加信息
$ type -a realpath
realpath is a function
realpath ()
{
f=$@;
if [ -d "$f" ]; then
base="";
dir="$f";
else
base="/$(basename "$f")";
dir=$(dirname "$f");
fi; …Run Code Online (Sandbox Code Playgroud) 为什么会出现此错误,我正在尝试获取此 set.conf
user@connect:~/testenv$ source $(cd $(dirname $0) && pwd)"/set.conf"
dirname: invalid option -- 'b'
Try 'dirname --help' for more information.
-bash: /home/tempuser/set.conf: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我尝试在命令提示符下添加 -- $0 效果很好,但是。如何在脚本中运行它?