2

Can i execute a linux command on my bash shell script. for example how can i execute ifconfig on shell script. when i execute the shell the output of ifconfig should come on terminal. is there any possibilities. Thanks in advance.

2
  • 1
    Bash shell script consists of Linux commands. ifconfig executed in a shell script will slow its result in terminal as usual. What's your REAL question? Jun 3, 2016 at 4:55
  • Can you show your shell script please?
    – BloodyEl
    Jun 3, 2016 at 8:12

2 Answers 2

1

This might well be the heart of the issue:

The main thing to remember is that (as vulgar approximation) the "prompt" where you run your commands is a shell. When you run a script on that prompt, it is run as a sub-process of the shell. The shell becomes the parent process.

Or, to quote Mendel Cooper in the Advanced Bash Scripting Guide:

A subshell is a separate instance of the command processor -- the shell that gives you the prompt at the console or in an xterm window. Just as your commands are interpreted at the command-line prompt, similarly does a script batch-process a list of commands. Each shell script running is, in effect, a subprocess (child process) of the parent shell.

http://www.tldp.org/LDP/abs/html/subshells.html

That guide has excellent information relative to your question.

What does that mean?

One of the most common issues when transferring a command-line to a script format is that when it is a script that is run as part of a larger command, the script must RETURN the value to the parent process (the shell). If it does not, then the script executes quietly and it is as if it wasn't in the shell command.

Often this type of problem can be solved by echo'ing a value or return'ing a value. Sometimes values are export'ed to global variables, and you can make your own. This does not sound like a case for global variables at all but just to give some examples.

I'll answer your questions directly as best I can with the information presented.

Q. Can i execute a linux command on my bash shell script?

A. Yes.

Q. for example how can i execute ifconfig on shell script.

A. Here is an example (assuming BASH):

cat NEW_NIC
    #!/bin/bash
    my_new_nic=enp101
    echo my_new_nic 

chmod 744 NEW_NIC
ifcfg NEW_NIC

Q. when i execute the shell the output of ifconfig should come on terminal.

A. Here is an example (assuming BASH):

cat SHOW_IF
    #!/bin/bash
    ifcfg  

chmod 744 SHOW_IF
SHOW_IF

More details about the script would allow for a better answer.

0

Yes you can execute any basic and complex commands on shell or terminal.

Incase you are confused remember : terminal = text input/output environment and shell = command line interpreter

You can refer below link if you need more explaination. https://askubuntu.com/questions/506510/what-is-the-difference-between-terminal-console-shell-and-command-line

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .