![readlink:非法选项——f](https://linux22.com/image/602124/readlink%EF%BC%9A%E9%9D%9E%E6%B3%95%E9%80%89%E9%A1%B9%E2%80%94%E2%80%94f.png)
最近该脚本运行良好,但几天后我在运行命令时收到这样的消息readlink -f "$0"
:
readlink: illegal option -- f
usage: readlink [-n] [file ...]
我正在运行以下代码来调试:
#!/bin/sh
DIR=`pwd`
RLPATH=`which readlink`
RLOUT=`readlink -f -- "${0}"`
DIROUT=`dirname -- ${RLOUT}`
echo "dir: ${DIR}"
echo "path: ${PATH}"
echo "path to readlink: ${RLPATH}"
echo "readlink output: ${RLOUT}"
echo "dirname output: ${DIROUT}"
输出:
# ./debug.sh
readlink: illegal option -- f
usage: readlink [-n] [file ...]
usage: dirname string [...]
dir: /home/svr
path: /sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin
path to readlink: /usr/bin/readlink
readlink output:
dirname output:
怎么了 ?
答案1
这是您正在运行的 FreeBSD 版本的问题。旧版本不支持 -f 选项。
解决这个问题的最简单方法是使用 GNU coreutils 端口 (/usr/ports/sysutils/coreutils),它会为您提供“greadlink”。这是我在脚本中使用的。