相关疑难解决方法(0)

未找到 realpath 命令

我有 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)

linux bash debian

35
推荐指数
4
解决办法
8万
查看次数

目录名无效选项`b`

为什么会出现此错误,我正在尝试获取此 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 效果很好,但是。如何在脚本中运行它?

bash

9
推荐指数
1
解决办法
9129
查看次数

标签 统计

bash ×2

debian ×1

linux ×1