我正在运行 Ubuntu 18.04 LTS。
我发现终端使用了该.bashrc
文件。我补充道:
export PATH="/home/keaton/scripts/:$PATH"
到该文件,然后在目录中创建一个脚本scripts
。简单的脚本是:
echo "Hello World"
echo $(which neqn)
cat $(which neqn)
当我进入终端并运行时,sh intro
我得到:
sh: 0: Can't open intro
我已经三次检查目录的路径scripts
是否正确输入。我是否输入或配置不正确?
答案1
而不是使用sh
尝试使用bash
.这对我有用:
$ bash intro
Hello World
/usr/bin/neqn
#! /bin/sh
# Provision of this shell script should not be taken to imply that use of
# GNU eqn with groff -Tascii|-Tlatin1|-Tutf8|-Tcp1047 is supported.
GROFF_RUNTIME="${GROFF_BIN_PATH=/usr/bin}:"
PATH="$GROFF_RUNTIME$PATH"
export PATH
exec eqn -Tascii ${1+"$@"}
# eof
当您调用脚本时,sh
您实际上正在使用,bash
但它运行在一种模式下,这使得它的行为就像是 Bash 前身的 shell 的更古老版本一样。
man bash
:
If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order. The --noprofile option may be used to inhibit this behavior. When invoked as an interactive shell with the name sh, bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. Since a shell invoked as sh does not attempt to read and execute commands from any other startup files, the --rcfile option has no effect. A non-interactive shell invoked with the name sh does not attempt to read any other startup files. When invoked as sh, bash enters posix mode after the startup files are read.