执行 file_server 安装后出现错误,当 deno 已经安装并且执行时没有任何错误

executing file_server giving error after install, when deno is already installed and executes without any error

我安装了 deno 并在 manual 期间练习成功。

但是,一旦我按照 File Server 的示例中概述的步骤进行安装和执行后...

$ file_server .
~/.deno/bin/file_server: 3: exec: deno: not found

我在 deno 的垃圾箱中有 file_server...

$ ls -al ~/.deno/bin/
total 86668
drwxr-xr-x 2 ***** *****     4096 Feb 10 23:53 .
drwxr-xr-x 3 ***** *****     4096 Feb  9 15:34 ..
-rwxr-xr-x 1 ***** ***** 88735456 Feb  4 05:48 deno
-rwxr-xr-x 1 ***** *****      134 Feb 10 23:53 file_server

我的 .bashrc 有...

export DENO_INSTALL="~/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
. "$HOME/.cargo/env"

deno 执行得很好...

$ deno
Deno 1.18.2
exit using ctrl+d or close()
> 1+ 2
3
> 

file_server 内容...

#!/bin/sh
# generated by deno install
exec deno run --allow-read --allow-net 'https://deno.land/std@0.125.0/http/file_server.ts' "$@"

uname -a...

$ uname -a
Linux ranjan-t410 4.19.0-17-amd64 #1 SMP Debian 4.19.194-3 (2021-07-18) x86_64 GNU/Linux

which 命令的结果...

:~$ which deno
:~$ which file_server
:~$

deno 版本...

$ deno --version
deno 1.18.2 (release, x86_64-unknown-linux-gnu)
v8 9.8.177.6
typescript 4.5.2

在这个例子之前,我已经能够deno run所有其他示例。

我哪里没做对,或者我漏了什么?



我电脑上的一些观察

  1. which 命令 return(s) 对于 denofile_server
  2. 都是空的
  3. $ ls -al /usr/bin/sh

    lrwxrwxrwx 1 root root 4 Sep 16 2020 /usr/bin/sh -> dash

  4. 如果我将 file_server 文件中的 shebang 从 #!/bin/sh 更改为 #!/bin/bash,那么它会起作用...

在没有更多信息的情况下,我认为问题是你的 $PATH 中的 sh 指向 dash,而不是 bash,所以你的 ~/.bashrc 并非由 dash 提供。如果你在 ~/.profile 中获取你的 ~/.bashrc (或者直接修改那里的环境变量),我认为它应该按预期工作。

参考:What is the dash equivalent for .bashrc?