linux - 可执行的 while 循环 : no such file or directory

标签 linux bash shell loops executable

我正在尝试编写一个简单的 bash 脚本来迭代可执行文件的输入参数。有问题的文件有两个参数。

以下脚本有效,在包含 .sh 文件和 .exe 文件的目录中运行终端:

#!bin/bash
./exec 1000 1

但是以下不是:

#!bin/bash
n=1
while [ $n -le 50 ]
do
    ./exec 1000 $n
    n=$(( n+1 ))
done

而是返回错误

script.sh: line 5: ./exec 1000 1: No such file or directory

script.sh: line 5: ./exec 1000 2: No such file or directory

等等。这意味着循环正在发生,但我不明白为什么它突然找不到可执行文件。我正在运行 Ubuntu 14.04。

最佳答案

它对我有用,一旦我修复了 shebang 行:

#!/bin/bash
n=1
while [ $n -le 50 ]
do
    ./exec 1000 $n
    n=$(( n+1 ))
done

原始版本会导致有关错误解释器的错误消息,但如果您在运行脚本时工作目录恰好是/,则可能会避免这种情况。

关于linux - 可执行的 while 循环 : no such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24562673/

相关文章:

php - 使用 PHP 在 ubuntu 中添加用户

java - 在java中运行linux命令发送带引号的电子邮件

bash - 如果命令输出包含某个字符串,我该如何测试(在一行中)?

arrays - bash 中是否有一个 array_combine 函数,我可以在其中从两个函数创建一个关联数组?

C:使用 scanf() 函数而不是 gets

php - 是否可以在不刷新网页的情况下在网页上显示交互式 shell 命令输出?

windows - 以毫秒为单位的打印批处理时间

linux - 检查已经运行的进程是否在 Linux 上重定向了 stdin?

java - 从远程系统提交 mapreduce 作业时出现异常

linux - If 语句 3 条件 Bash