在 Windows 上的 ubuntu 中执行.sh文件

Execute .sh file in ubuntu on windows

本文关键字:执行 sh 文件 ubuntu Windows 上的      更新时间:2023-10-16

我创建了一个文件,1.sh,作为

C++ -C 文件1.cpp

C++ 文件1.o -o 文件1

我试图在Windows上的bash Ubuntu上执行它。它告诉我

:没有这样的文件或目录

C++:致命错误:无输入文件

编译终止。

但是,如果我执行

C++ -C 文件1.cpp

C++ 文件1.o -o 文件1

直接,文件(File1.cpp(可以正常遵守。

我的问题是,文件不起作用的原因是什么.sh以及如何解决它?

实际上,我想将其写为评论,但没有可用的格式。(当这个答案过时时,我会删除它。

我刚刚尝试了这个(在cygwin的bash上使用g ++(:

$ g++ -c nothing.cc
g++: error: nothing.cc: No such file or directory
g++: fatal error: no input files
compilation terminated.
$

当然,我当前的工作目录中没有文件nothing.cc在哪里......

所以,我的猜测(从 shell 脚本启动时C++在错误的工作目录中运行(可能是合理的......

正如我已经建议的那样:插入一个

echo "$PWD"

在 shell 脚本的开头可以肯定。

更新:

出于好奇,我也尝试了这个(cygwin,再次bash(:

$ c++ -c nothing.cc
c++: error: nothing.cc: No such file or directory
c++: fatal error: no input files
compilation terminated.
$

现在,它看起来与OP非常相似。

唯一让我感到困惑的事实:OP 的错误消息看起来像编译器是否没有得到任何输入:

$ c++
c++: fatal error: no input files
compilation terminated.
$

但我相信事实并非如此,因为在 OP 中它以
: No such file or directory .
因此,看起来缺少一些文本...