|
From: | David Braun |
Subject: | Re: stat(1) print formats |
Date: | Sat, 22 Nov 2014 06:58:26 -0500 |
print hello$symlink[0]
Hello David,
You sent this message just to me.
Did you mean it as private or as a reply a coreutils' mailing list ?
In any case, - I'm answering in private,
but you are welcome to forward my reply to the mailing list.
On 11/21/2014 07:15 PM, David Braun wrote:
But I'd still like to argue for a simple %something that outputs just
the link destination/target/value (whatever you what to call it).
This would make the processing you suggested unnecessary. And I think
the current behavior produces something that isn't very useful to
start with.
That is up to the coreutils developers - I'm not one...
BTW - why did you make your example so darned difficult to read?!
:)
Yes, not only it was difficult to read, it was tricky to construct...
My point was to illustrate that quoting is used to remove ambiguity with symlinks.
if both the name of the src and dest are 'simple' (e.g. no special characters, no white space,
no quotes, no dash or less-than characters) then parsing using shell would be trivial (which is something you've asked about).
With my contrived example I hoped to show that even a complicated case can be parsed without ambiguity.
Perhaps I went too far...
Wouldn't it have been simpler (if not exhaustive) to have said<...>
and proceed from there? While all the special characters in your
example may cover a lot of ... special cases they don't help
readability at this point in the discussion. Also my suggestion would
reduce you example to
Yes, I would have been simpler.
I probably should have started with a more approachable example.
But a simpler example would still leave open the question of what happens
if the filenames themselves have quotes - how does that work in conjunction with %N .
Or worse - if they have "->" in them...
Also my suggestion would reduce you example to
$ stat -tc "SRC=""> DST=%N" hello
SRC=""> DST=world
and the split command line is only because stat doesn't process
escapes like '\n'. This assumes that '-t' in combination with '-c'
makes %N return an unadorned (like %n) destination.
Agreed, if your suggestion is incorporated into a 'stat' option, that this would be much simpler.
However, I'm not sure 'stat' is the optimal tool for such things (especially if it depends on parsing the results, and making assumptions about file names).
Perhaps a better way would be to use
test -h "$SRC" && DST=$(readlink -- "$SRC") || DST="$SRC"
Which will set DST to be either SRC (if it's a file), or resolve the symlink of SRC if it's a symlink.
Regards,
- Assaf
[Prev in Thread] | Current Thread | [Next in Thread] |