【发布时间】:2013-08-27 00:28:53
【问题描述】:
我从来没有写过 .sh 代码,如果这个问题看起来太明显了,很抱歉:
我有一个在 ubuntu 控制台中运行的可执行文件“executable1”,如下所示: ./executable1 文件名1
这很好用。
考虑到我需要在很多文件上运行此代码(1000 个),我编写了一个 sh 脚本,在其中存储了所有文件名并尝试使 executable1 对它们起作用,如下所示:
#!/bin/bash
filesNames=(fileName1 fileName2 [etc] fileName1000)
numberFiles=1000;
for i in `seq 1 $numberFiles`
do
./executable1 ${filesNames[$i]} > results.txt &
done
我在我的 shell 中运行代码(名为 scriptName.sh),如下所示:
bash scriptName.sh
但是,我收到以下错误:
./executable1: No such file or directory
我不明白,因为当我单独在 shell 中执行 ./executable1 时,它工作得很好......
【问题讨论】:
-
执行
bash scriptname.sh命令时你在哪个目录?要使./executable1工作,该文件必须存在于当前工作目录中。您可以尝试在脚本中使用绝对路径(例如/some/directory/executable1)以确保找到可执行文件1。 -
将“相对”路径替换为完整路径,即 /path/to/executable1。您可能会发现其他与 PATH 相关的问题,祝您好运。
-
可执行文件 1 与 scriptname.sh 位于同一目录中。然而,当我编写完整路径时,它可以工作......谢谢。但是你知道为什么我需要写完整的路径吗?
标签: linux shell executable sh