Results 1 to 10 of 16
if [ `readlink $0` ]; then
scriptname=`readlink -f $0`
else
scriptname="$0"
fi
is the beginning of a script, not written by me. When run it returns the message;
readlink: scriptname ...
- 03-27-2009 #1Just Joined!
- Join Date
- Mar 2009
- Posts
- 15
readlink -f Invalid argument
if [ `readlink $0` ]; then
scriptname=`readlink -f $0`
else
scriptname="$0"
fi
is the beginning of a script, not written by me. When run it returns the message;
readlink: scriptname: Invalid argument - I imagine this relates to the -f argument (option)?
Any ideas on what the author might be trying to do with -f ?
Do you think I'm correct in thinking -f is the problem?
The readlink does stick ./ on the front of the scriptname and I'm also guessing this is both normal and correct? Is that normal and correct?
Any help? Any ideas? Please Please Please
- 03-27-2009 #2Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
The fragment seems to work for me in this:
Running as s1:Code:#!/usr/bin/env bash # @(#) s1 Demonstrate readlink. echo set +o nounset LC_ALL=C ; LANG=C ; export LC_ALL LANG echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG" echo "(Versions displayed with local utility \"version\")" version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) readlink set -o nounset echo echo " Results:" if [ `readlink $0` ] then scriptname=`readlink -f $0` else scriptname="$0" fi echo " scriptname is :$scriptname:" exit 0
and running as a soft link my_link1:Code:% ./s1 Environment: LC_ALL = C, LANG = C (Versions displayed with local utility "version") OS, ker|rel, machine: Linux, 2.6.11-x1, i686 Distribution : Xandros Desktop 3.0.3 Business GNU bash 2.05b.0 readlink (coreutils) 5.2.1 Results: scriptname is :./s1:
It might be useful to place the fragment in a short test script as I did, and then paste the code and the result.Code:% ./my_link1 Environment: LC_ALL = C, LANG = C (Versions displayed with local utility "version") OS, ker|rel, machine: Linux, 2.6.11-x1, i686 Distribution : Xandros Desktop 3.0.3 Business GNU bash 2.05b.0 readlink (coreutils) 5.2.1 Results: scriptname is :/home/drl/try/user-problem/575/s1:
Just a guess -- are you using a really old Linux system? ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 03-27-2009 #3Just Joined!
- Join Date
- Mar 2009
- Posts
- 15
Hi drl, thanks for your reply
Here's what I put in;
echo
set +o nounset
LC_ALL=C ; LANG=C ; export LC_ALL LANG
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) readlink
set -o nounset
echo
echo " Results:"
if [ `readlink $0` ]
then
scriptname=`readlink -f $0`
else
scriptname="$0"
fi
echo " scriptname is :$scriptname:"
exit 0
And here-s what I got out
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
Results:
readlink: ./freecast-tracker: Invalid argument
scriptname is : ./freecast-tracker
I used the same filename as previously, to continue as consistent as possible.
I'm using DSL (damn small linux) which uses a 1.4 kernel and it's on an old P1 laptop. It's the only distro for old style machines I could get to boot and run and install as a layman (I'm not a linux bod, give me point and click every time lol).
Version didn't seem to work here? (I can do java -version and it gives me a return).
I probably haven't loaded dsl up with all the possible goodies, can't remember if I did GNU Utils etc this time round as, when the electricity clicks off, as it does here in Spain reasonably often, the fs goes wonky and I've had to reinstall, and I try only to download the minimum I think I may need to do the job I want to do.
Does any of this mean anything to you? Do you know what that -f might be supposed to do?
Thanks for any more help you can give?
- 03-27-2009 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
The version control statement is local to my site. It is set up in the script so that it is a do-nothing if it is not available.
Does your man page look like this?
cheers, drlCode:SYNOPSIS readlink [OPTION]... FILE DESCRIPTION Display value of a symbolic link on standard output. -f, --canonicalize canonicalize by following every symlink in every component of the given path recursively -- excerpt from man readlinkWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 03-27-2009 #5Just Joined!
- Join Date
- Mar 2009
- Posts
- 15
Hi again, very quick, thanks

Ok, man page says
readlink [-f] FILE
Display the value of a symlink
Options:
-f Canonicalize by following all symlinks
Well, I'm more in the habit of searching on the net than in man pages. Canonicalise doesn't appear in my dictionary, does it mean to follow the links in a saintly or religious fashion?
Doesn't readlink $0 just mean that it´s trying to return the name of the current script? In which case would it ever be able to return any more than this unique value however many symlinks were searched? In which case wouldn't -f be completely redundant. So, is the error being produced because the command is unable to associate the -f option with the $0?
Would the -f option become relevant when the command was being given a directory path to search, in which case it may be able to continue returning values depending however many it might find? Of course, then it would really be readlink [option] dir rather than file.
Yes, it's true, I haven't really got any idea what symlinks are or do, but am I close-ish?
- 03-27-2009 #6Just Joined!
- Join Date
- Mar 2009
- Posts
- 15
Damn, I just took the -f out of the test script and still got the same error

Damn!
Any more help? (asking in saintly and religious piety)
- 03-27-2009 #7Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Links are alternate names for files. They can be hard links or soft links. The readlink command allows one to follow the softlink until it gets to the real file.
Now that we know your version of readlink allows option "-f", we can move ahead to other possibilities. Please add the following line:
before the first echo statement.Code:echo " name of script is :$0:"
I also noticed that the first line of the script --
was not in the report of your test script -- is that truly in the file? ... cheers, drlCode:#!/usr/bin/env bash
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 03-27-2009 #8Just Joined!
- Join Date
- Mar 2009
- Posts
- 15
Hmm, I don't have a directory /usr/bin/env - there's no env
Lines preceded by # are comments only and not processed by scripts? Am I missing something subtle here?
Anyway, I`ll do it just as you say, as you're technical
I did stick in a few echo's to see where the little script was going, it seems not to like if [ 'readlink $0`] and has been moving straight on to else. after I put some exho's in it seemed to process then and produced the full directory path of the script and not just the script name (preceded by ./)
Ok, brb
- 03-27-2009 #9Just Joined!
- Join Date
- Mar 2009
- Posts
- 15
Ok, output now reads;
(versions displayed .......
name of script is :./freecast-tracker:
Results:
readlink: ./freecast-tracker: Invalid argument
scriptname is :./freecast-tracker:
- 03-27-2009 #10Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
The first line of a script often is:
if you don't have /usr/bin/env, then please make this the first line:Code:#!somepath-to-an-executable
That first line would be taken as a comment, but the "#!" makes it special. You may see it referred to as a shebang line: she for shell, and bang is an old unix name for the exclamation point ... cheers, drlCode:#!/bin/bash
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote