Skip to content

How to receive name with which the script was invoked #9043

Closed Answered by faho
septatrix asked this question in Q&A
Discussion options

You must be logged in to vote

The above always return the resolved path

The path will be absolutized, because fish passes the absolute path as argv[0], but it won't be "resolved".

E.g. create /tmp/foo.fish:

#!/usr/bin/fish
echo Hi my name is (status filename)

make it executable, run it via /tmp/foo.fish or ./foo.fish and it will print "Hi my name is /tmp/foo.fish".

But make a symlink /tmp/bar.fish, pointing to /tmp/foo.fish, and run that, and you'll get "Hi my name is /tmp/bar.fish".

Tbh I don't see the need in doing anything else for help texts or busybox-like argv[0]-based tool changing. The full path is usable, the basename is whatever file you were executed through - either of which could serve as your name.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@septatrix
Comment options

Answer selected by septatrix
Comment options

You must be logged in to vote
2 replies
@septatrix
Comment options

@floam
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants