Question

I am an absolute beginner with Linux Operating system and just for fun in terminal I typed system() what happened next is as below:

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

Here I want to know that what is system() ? what is it's role here? why I got error in int main() line? What can we do with C/C++ programming in terminal?

Was it helpful?

Solution

Here I want to know that what is system()?

When you said system() and hit Enter, the shell thought that you were about to define a shell function named system.

Anything starting with # is interpreted as a comment by the shell.

You got an error in the int main() line because your function body had not started.

The syntax for a shell function is:

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

An example of how you might define a function and use it:

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

OTHER TIPS

You can't do anything with C/C++ programming at terminal. The terminal doesn't recognize c/c++ language. The linux terminal recognize bash,csh scripting language depending on which shell are you using. Thus you get error for main() since their is no such thing in bash scripting. For c/c++ program you have c/c++ compiler like gcc, g++ in linux and for compiling you have to type gcc/g++ hello.c/.cpp. Go through this basic tutorial http://www.ee.surrey.ac.uk/Teaching/Unix/

Regarding system(), it is used to execute shell command in linux http://linux.die.net/man/3/system

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top