本文介绍了从 Shell 脚本运行可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法启动从 shell 脚本创建的可执行文件.我想通过使用不同的命令行选项多次运行程序来自动测试,以验证它是否正常工作.

I am having trouble launching an executable that I have created from a shell script. I would like to automate testing by running the program many times with different command line options to verify it is working.

当我输入echo $SHELL时,显示/bin/sh.

以下是我的shell脚本:

The following is my shell script:

#!/bin/sh
clear
echo "Running first test."
./myProgram
exit 0

当我运行脚本 (sh myScript.sh) 时,myProgram 位于同一目录中,我看到以下输出:

When I run the script (sh myScript.sh), with myProgram in the same directory, I see the following output:

Running first test.
: not foundsh: line 4:

当执行程序 ./myProgram 时,它按预期运行,没有命令行选项.

When executing the program ./myProgram, it runs as expected with no command line options.

我也试过:我的程序./myProgram &我的程序基于对有些类似问题的回答,但它们都会导致上述错误消息.

I have also tried: myProgram ./myProgram & myProgram &based on answers to somewhat similar questions, but they all result in the above error message.

推荐答案

你的换行符乱七八糟.使用 dos2unix 修复.

Your newlines are goofed. Use dos2unix to fix.

这篇关于从 Shell 脚本运行可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 22:18