readlink man/help does not match command flags

Asked by jpvrlaone on 2012-05-12

I stumlbed accross a problem where a script kept failing when running the readlink command.
It did not like the use of the -f flag which is supported in the man page. I got past the problem using /usr/lib/klibc/bin/readlink found through a search of the system. More details can be found in the forum using the tag "readlink".
What is going on with the readlink command?

Ubuntu 12.04 (precise)
2.6.38-8-generic
Intel(R) Core(TM) i5 CPU 650 @ 3.20GHz

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu coreutils Edit question
Assignee:
No assignee Edit question
Solved by:
actionparsnip
Solved:
2012-05-15
Last query:
2012-05-15
Last reply:
2012-05-13

I suggest you report a bug

You should also reboot to the Precise kernel, your kernel version is not that of Precise.

I use readlink often, including -f, and have found no problems with it. Please link to the forum discussion.

jpvrlaone (jpv4433) said : #3

I updated my kernel earlier but I see what is going on now. When I test readlink from the command line as a non-root user (readlink -f "$0") the dollar zero passes"-bash" as a value where the first letter after the dash is "b" and is considered an invalid flag. Likewise, when this is done as root the dollar zero passes "-su" where "s" is accepted since it is valid but the "u" is not. So apparently the problem stems from the use of $0 when used within a script as opposed to a command line.
I would like to rerun the original install script to see why it was failing at the readlink juncture but I "prefer to let sleeping dogs lie".

Linux XXXxxxx 3.2.0-24-generic #37-Ubuntu SMP Wed Apr 25 08:43:22 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

[ user ~ ] $ echo "$0"
-bash
[ user ~ ] $ readlink -f "$0"
readlink: invalid option -- 'b'
Try `readlink --help' for more information.

[ user ~ ] $ su -
Password:
root@pc:~# echo "$0"
-su
root@pc:~# readlink -f "$0"
readlink: invalid option -- 'u'
Try `readlink --help' for more information.
root@pc:~# man readlink

I suggest you re-disable the root account and stick to sudo