如何使用 Bourne Shell 运行我的 C 程序?

thi*_*ary 2 sh

通过切换到我的 C 程序的目录并以./. 但是,我不确定为什么更改到目录然后键入sh [Program Name]会出现此错误:

Fortune_Teller_5000: 1: Fortune_Teller_5000: Syntax error: "(" unexpected
Run Code Online (Sandbox Code Playgroud)

和:

./Fortune_Teller_5000: 1: ./Fortune_Teller_5000: Syntax error: "(" unexpected
Run Code Online (Sandbox Code Playgroud)

我在 bash 手册页中读到该sh命令是一个不读取.bashrc文件的 shell ,所以我有点困惑为什么我不能用它来运行我制作的程序。我确实根据 HP Linux Imaging and Printing 页面上的说明使用它来安装我的打印机驱动程序。

Web*_*ide 20

键入sh program_name假定program_name是一个 shell 脚本并执行该脚本(因此它必须使用 sh/bash 语言)。如果Fortune_Teller_5000是二进制文件(编译后的 C 程序,甚至 C 源代码),则运行sh Fortune_Teller_5000将不会按预期工作。

这里有两种方法可以做到:

  1. 键入sh然后按ENTER键,然后键入./Fortune_Teller_5000(你可能需要cd到正确的目录)
  2. 输入sh -c ./Fortune_Teller_5000sh -c /path/to/folder/Fortune_Teller_5000

  • 顺便说一句,在另一个 shell 中运行你的 C 程序有什么意义?您没有以任何方式使用它的任何功能,因此您可以直接启动您的程序。 (3认同)

Ant*_*gan 9

运行sh [Program Name]指示sh程序执行名为[Program Name]so的 shell 脚本,如果此文件是 C 程序,则该命令将失败。

shPOSX 规范(标准命令语言解释器)指出, for 的参数sh应该是“包含命令的文件的路径名”。