-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[suggestion] emulate readlink using posix ls #5
base: master
Are you sure you want to change the base?
Conversation
@@ -109,3 +109,7 @@ _gnu_stat_readlink() { | |||
_bsd_stat_readlink() { | |||
stat -f %Y -- "$1" 2>/dev/null | |||
} | |||
|
|||
_posix_ls_readlink() { | |||
LC_TIME=POSIX ls -l -- "$1" | sed -e 's/^.\{11\}\ *[0-9]\{1,\}\ *[a-zA-Z\._@\$-]\{1,\}\ *[a-zA-Z\._@\$-]\{1,\}\ *[0-9]\{1,\}\ *[^ ]*\ *[0-9]\{1,2\}\ *[^\ ]*\ \(.*\)/\1/g' -e 's/.* -> //g' 2>/dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, it'll take me a little bit to wrap my head around that regex.
Does the g
flag do anything when the substitution match is anchored to the beginning of the line with ^
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the g flag does nothing. it's just my habbit when i write regex.
Thanks for the PR! I think you're right, Do you see any reason to keep around the stat readlink emulation? I'm inclined to get rid of it if there's ls readlink emulation. Also, it might be nice to have an automated test or two around this change, but I'm not super worried about it since it's a bonus feature that's basically a big regex. I can test this out and verify that it seems to work right sometime in the next few days. Or if someone else wants to try it out and vouch for the change, I'd consider merging it sooner. |
the ls readlink emulation is just suggestion. so i didnt consider removing the stat readlink emulation. and i was careless about an automated test. it's my fault. i'll add automated test soon. i didnt usually pay attention about automated test. if i may, can i ask you an advice while i add an automated test? |
ls(1) stderr redirect to /dev/null
bugfix posix_ls_readlink
stat(1) is not posix compatible.
emulated readlink using ls