Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Recently the script was working fine, but from some days I'm receiving such message, while running the readlink -f "$0" command:

readlink: illegal option -- f
usage: readlink [-n] [file ...]

I was running the following code to debug:

#!/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}"

Output:

# ./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:

What is wrong ?

share|improve this question
    
May be readlink binary was overwritten? Check, that stat and readlink has same inode: ls -li /usr/bin/readlink /usr/bin/stat –  citrin Dec 7 '12 at 10:45
    
If you wan to know real directory, where script located, better to use: dirname $(realpath "$0") –  citrin Dec 7 '12 at 10:47
    
@citrin Yes: 1083670 -r-xr-xr-x 2 root wheel 16760 May 4 2011 /usr/bin/readlink 1083670 -r-xr-xr-x 2 root wheel 16760 May 4 2011 /usr/bin/stat –  Scott Dec 7 '12 at 11:04
    
@citrin # dirname $(realpath "$0") Illegal variable name. –  Scott Dec 7 '12 at 11:52
1  
8.2 has the -f option, so your stat binary is modified. I suggest to rebuild and install it: cd /usr/src/usr/bin/stat && make install –  arved Dec 10 '12 at 11:13
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.