我正在尝试编写一个简单的 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/