带有相对路径的fish执行文件

发布于 2025-01-09 04:30:34 字数 2617 浏览 1 评论 0原文

我遇到一个问题,无法运行 fish x.fishfish ./x.fish,但可以运行 fish (pwd)/ x.fish,又称使用文件的绝对路径而不是相对路径或使用 .。我在以前的安装中没有遇到过这个问题,但这次我的设置有点不同,所以我很感激任何建议。

版本: fish --version = fish,版本 3.3.1

设置:在 Windows 11 WSL 中安装 fish 作为 shell,并将其设置为默认 shell。

我的脚本名为 main.fish

echo "in main.fish script"

main.fish 的父目录中运行:

fish main.fish = main.fish :没有这样的文件或目录

fish /main.fish = ./main.fish:没有这样的文件或目录

fish (pwd)/main .fish = 在 main.fish 脚本中

是什么阻止了我使用相对路径运行鱼文件?也许不相关,将文件设置为可执行文件并运行 ./main.fish 并添加 #! /usr/bin/fish 结果为./main.fish:没有这样的文件或目录

![在此处输入图像描述

我被难住了。重申一下,任何帮助将不胜感激。

编辑:

我运行了 strace Fish.main,它很大,但以

openat(AT_FDCWD, "main.fish", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
dup(2)                                  = 3
fcntl(3, F_GETFL)                       = 0x8002 (flags O_RDWR|O_LARGEFILE)
openat(AT_FDCWD, "/usr/share/locale/C.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/C.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/C/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/C.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/C.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/C/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
fstat(3, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x4), ...}) = 0
write(3, "main.fish: No such file or direc"..., 37main.fish: No such file or directory
) = 37
close(3)                                = 0
getpid()                                = 11251
getpgrp()                               = 11248
ioctl(0, TIOCGPGRP, [11248])            = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, SNDCTL_TMR_START or TCSETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
exit_group(127)                         = ?
+++ exited with 127 +++

I'm having an issue where I can't run fish x.fish or fish ./x.fish, but I can run fish (pwd)/x.fish, AKA using an absolute path to my file instead of a relative one or with .. I haven't had this issue in previous installations, but my setup is a bit different this time so I'd appreciate any advice.

Version:
fish --version = fish, version 3.3.1.

Setup: installed fish as shell in Windows 11 WSL, and set it as default shell.

My script named main.fish:

echo "in main.fish script"

running in the main.fish's parent directory:

fish main.fish = main.fish: No such file or directory

fish /main.fish = ./main.fish: No such file or directory

fish (pwd)/main.fish = in main.fish script

What is stopping me from running a fish file with a relative path? Maybe unrelated, setting the file to executable and running ./main.fish and adding #! /usr/bin/fish results in ./main.fish: No such file or directory.

![enter image description here

I'm stumped. Reiterating, any help would be appreciated.

EDIT:

I ran strace fish.main, and it's large but ends with

openat(AT_FDCWD, "main.fish", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
dup(2)                                  = 3
fcntl(3, F_GETFL)                       = 0x8002 (flags O_RDWR|O_LARGEFILE)
openat(AT_FDCWD, "/usr/share/locale/C.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/C.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/C/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/C.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/C.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/C/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
fstat(3, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x4), ...}) = 0
write(3, "main.fish: No such file or direc"..., 37main.fish: No such file or directory
) = 37
close(3)                                = 0
getpid()                                = 11251
getpgrp()                               = 11248
ioctl(0, TIOCGPGRP, [11248])            = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, SNDCTL_TMR_START or TCSETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
exit_group(127)                         = ?
+++ exited with 127 +++

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白首有我共你 2025-01-16 04:30:34

这个问题在 https://github.com/fish-shell/fish- 中得到了回答shell/issues/9040

Fish 总是读取其配置,即使是非交互式的。

这意味着如果您在 config.fish 中有 cd ~ ,那么运行

fish ./x.fish

将启动 Fish,它将 cd 到主目录,然后尝试在主目录中运行“x.fish”目录。

解决方案是使用 status is-interactive 保护 cd ~:(

if status is-interactive
    cd ~
end

或完全删除它)

This was answered in https://github.com/fish-shell/fish-shell/issues/9040.

Fish always reads its configuration, even non-interactively.

That means if you have a cd ~ in config.fish, then running

fish ./x.fish

will start fish, which will cd to the home directory, and then attempt to run "x.fish" in the home directory.

The solution is to guard that cd ~ with status is-interactive:

if status is-interactive
    cd ~
end

(or remove it entirely)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文