需要帮助修复 bash 中的奇怪路径错误

需要帮助修复 bash 中的奇怪路径错误

我下载了两个可执行文件,并尝试将其添加到路径中。它们位于

/home/user/folder

具体文件是

/home/user/folder/app1
/home/user/folder/app2

app1 和 app2 都将可执行标志设置为全部(用户、组、其他)。

如果我在 /home/user/folder 中并执行以下命令,我可以执行这些文件

./app1
./app2

但是我无法从其他地方运行它们。我将这行添加到我的 .profile 中

PATH="$PATH:/home/user/folder"

然后使用

. /home/user/.profile

当我使用命令完成(按 Tab 键)时,我可以看到 app1 和 app2。但是,当我尝试使用以下命令运行 app1 或 app2 时,会发生以下情况(以下仅显示“app1”,但“app2”也是如此)

user@comp:~$ app1
-bash: app1: command not found
user@comp:~$ /home/user/folder/app1 
-bash: app1: command not found
user@comp:~/folder$ ./app1
(program runs)

我被难住了 :),我肯定错过了一些简单的事情。谢谢你的帮助!!

更新

好的,我在路径中发现了一些错误,我想我已经修复了这些错误,但现在它无论如何都无法运行 - 出于某种原因,我认为这是向前迈出的一步。感谢您建议以下步骤,以下是它们的输出:

user@computer:~$ echo $PATH
/usr/share/fsl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/matlab/bin:/usr/local/VoxBo/bin:/usr/local/itt/idl64/bin:/usr/local/afni/bin/:/usr/local/mricron:/usr/lib/voxbo/bin:/home/user/folder:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11/:/usr/games/:/usr/local/matlab/bin:/usr/local/VoxBo/bin/:/usr/local/itt/idl64/bin:/usr/local/afni/bin/:/usr/local/mricron/
user@computer:~$ typeset -p PATH
declare -x PATH="/usr/share/fsl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/matlab/bin:/usr/local/VoxBo/bin:/usr/local/itt/idl64/bin:/usr/local/afni/bin/:/usr/local/mricron:/usr/lib/voxbo/bin:/home/user/folder:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11/:/usr/games/:/usr/local/matlab/bin:/usr/local/VoxBo/bin/:/usr/local/itt/idl64/bin:/usr/local/afni/bin/:/usr/local/mricron/"
user@computer:~$ type app1
app1 is /home/user/folder/app1
user@computer:~$ type app2
app2 is /home/user/folder/app2
user@computer:~$ app1
bash: /home/user/folder/app1: No such file or directory
user@computer:~$ app2
bash: /home/user/folder/app2: No such file or directory
user@computer:~$ /home/user/folder/app1
bash: /home/user/folder/app1: No such file or directory
user@computer:~$ /home/user/folder/app2
bash: /home/user/folder/app2: No such file or directory
user@computer:~$ cd /home/user/folder
user@computer:~/folder$ app1
bash: /home/user/folder/app1: No such file or directory
user@computer:~/folder$ ./app1
bash: ./app1: No such file or directory
user@computer:~/folder$ ./app2
bash: ./app2: No such file or directory
user@computer:~/folder$ ls -l
total 29384
-rwxr-xr-x 1 user user 14949776 2011-02-03 11:09 app1
-rwxr-xr-x 1 user user 15137300 2011-02-03 11:10 app2
user@computer:~/folder$

感谢大家的意见!

答案1

我知道其中一些是重复的......但是......

编辑 BASH RC 文件:

vim ~/.bashrc

出口路径:

export PATH=$PATH:/home/$username/folder/

如果您不想再次登录来获取路径,请将其 SOURCE :

source ~/.bashrc

确保该文件是您的且可执行:

chown -R $username /home/$username/folder/
chmod +x /home/$username/folder/app*

尝试运行:

cd
app1
app2

仍然有找不到命令错误?那么,app1 和 app2 是什么类型的文件?

file /home/$username/folder/app1
file /home/$username/folder/app2

如果它们是文本文件,则可能是脚本,如 BASH 或 Python。如果是这样,请使用编辑器打开它们,看看是否可以找到问题的根源。如果您粘贴文本文件的任何内容(如果它们确实是文本文件),请务必包含第一行 - “文件魔法”,如/bin/sh #!/bin/sh 复制代码, 例如。

相关内容