【问题标题】:What is system() in linux Terminal?linux终端中的system()是什么?
【发布时间】:2013-11-08 09:43:01
【问题描述】:

我是 Linux 操作系统的绝对初学者,只是为了好玩,我在终端输入了 system() 接下来发生的事情如下:

satish@satish-Inspiron-N5010 ~ $ system()
>#include<iostream>
>int main()
bash: syntax error near unexpected token 'int'
satish@satish-Ispiron-N5010~ $

这里我想知道什么是 system() ?它在这里的作用是什么?为什么我在 int main() 行中出现错误?我们可以在终端中使用 C/C++ 编程做什么?

【问题讨论】:

  • 我对 C 或 C++ 不太熟悉,但也许 this 页面可以解决问题。

标签: shell terminal linux-mint


【解决方案1】:

您无法在终端上使用 C/C++ 编程进行任何操作。终端无法识别 c/c++ 语言。 linux 终端根据您使用的 shell 识别 bash、csh 脚本语言。因此你会得到 main() 的错误,因为它们在 bash 脚本中没有这样的东西。对于 c/c++ 程序,你有 c/c++ 编译器,如 gcc,linux 中的 g++,编译你必须输入 gcc/g++ hello.c/.cpp。看完这个基础教程http://www.ee.surrey.ac.uk/Teaching/Unix/

关于system(),用于在linux中执行shell命令http://linux.die.net/man/3/system

【讨论】:

  • 好的。顺便说一句,很好的区分。我得到了你想要解释的东西。除了你说的这些,我想问一下 system() 在终端中做了什么?希望你明白我想问什么。
【解决方案2】:

这里我想知道system()是什么?

当你说system()并按Enter时,shell认为你要定义一个名为system的shell函数。

# 开头的任何内容都被shell 解释为注释。

int main() 行出现错误,因为您的函数体尚未启动。

shell 函数的语法是:

function: function name { COMMANDS ; } or name () { COMMANDS ; }
    Define shell function.

如何定义和使用函数的示例:

$ system()
> { echo $SHELL; }
$ system
/bin/bash

【讨论】:

  • 很好地解释了......明白了。谢谢... :) :)
猜你喜欢
  • 1970-01-01
  • 2015-10-24
  • 2016-05-29
  • 1970-01-01
  • 1970-01-01
  • 2018-03-11
  • 1970-01-01
  • 2022-06-14
  • 1970-01-01
相关资源
最近更新 更多