Skip to content
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

dirname replacement #9

Closed
LordAro opened this issue Oct 13, 2013 · 2 comments
Closed

dirname replacement #9

LordAro opened this issue Oct 13, 2013 · 2 comments

Comments

@LordAro
Copy link

LordAro commented Oct 13, 2013

I'm not entirely sure if this is a bug, so please forgive me if it's a problem with my script instead

shellcheck suggests that i replace "dirname $0" with "${var%/*}"
however, when i run the script with "bash scriptname" or "sh scriptname", the parameter expansion does not result in the same string:
dirname: "."
parameter expansion: "scriptname"

hope that helps

@koalaman
Copy link
Owner

The two are often interchangable, but in this case, for paths with trailing slashes, and in your unquoted case when the invoked name contains whitespace, the results are not identical. dirname and basename handle some edge cases well, even though it's slower and harder to use right. I'll keep it mind and see how helpful this suggestion actually is.

PS: dirname $0 is not a reliable way of getting the directory the script is in. In particular it fails when you invoke the script from $PATH.

@ptman
Copy link

ptman commented Oct 22, 2013

I also think the checks on basename and dirname may be a bit aggressive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants