-
Fish always seem to use the absolute path when invoking scripts with a shebang. E.g.: #!/usr/bin/fish
echo (status filename)
# or
#!/usr/bin/sh
echo $0 The above always return the resolved path even when invoked as This is problematic as it is often required to get the way the command was invoked, e.g. for help texts. Is there any way to receive this information otherwise? I start to fear not however this goes against the widespread convention that |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
The path will be absolutized, because fish passes the absolute path as argv[0], but it won't be "resolved". E.g. create #!/usr/bin/fish
echo Hi my name is (status filename) make it executable, run it via 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. |
Beta Was this translation helpful? Give feedback.
-
argv[0] can contain arbitrary contents. A common special case is prefixing something with You shouldn't really rely on it for anything other than printing a nice error or figuring out which busybox widget you are. For either of those,
I don't think it's all that simple - it would have to work both with execve and the new posix_spawn hotness (we use the latter and fall back on the former when we have to). I wouldn't be interested in reviewing it, because I don't see the use case. |
Beta Was this translation helpful? Give feedback.
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
: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.