LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Command execution order (https://www.linuxquestions.org/questions/programming-9/command-execution-order-4175473721/)

mahendra singh 08-17-2013 10:54 AM

Command execution order
 
Appreciate for the fast reply

Dear Friends,

I have a script which has 2 commands in it.
Command 1 takes long time to do its job.

ex:

vi t.ksh

#bin/bash
grep "m" *.txt ---command 1
grep "t" *.ksh ---command 2


Is there a way that i don't wait the completion of command 1 in script and script proceed with next execution of command.?

Regads,
Mahendra Singh

eSelix 08-17-2013 11:20 AM

Yes, append at end of command "&". It will send this process to background.
Code:

#!/bin/bash
grep "m" *.txt &
grep "t" *.ksh


mahendra singh 08-17-2013 11:31 AM

Quote:

Originally Posted by eSelix (Post 5010950)
Yes, append at end of command "&". It will send this process to background.
Code:

#!/bin/bash
grep "m" *.txt &
grep "t" *.ksh




I did but its still throwing the output on console for first command?

schneidz 08-17-2013 11:52 AM

Quote:

Originally Posted by mahendra singh (Post 5010952)
I did but its still throwing the output on console for first command?

the obvious question is: would redirecting the output to a file help ?

eSelix 08-17-2013 02:41 PM

And what you want to do with the output of first command?

reza_zah1991 08-17-2013 04:11 PM

Code:

reza@reza-HP-1000:~$ cat /etc/passwd |grep 'root' &>file &
[1] 5636
reza@reza-HP-1000:~$ cat file
root:x:0:0:root:/root:/bin/bash
[1]+  Done                    cat /etc/passwd | grep --color=auto 'root' &>file

with >&file you send the stdout & stderr to a file

and with the & at the end of the line you send the process to the background

if you have problem with lastLine,,youcan read the file & delete the last line with sed command

mahendra singh 08-18-2013 09:35 AM

Hi All,

Yes issue got resolved, I have put the first process or command background(&) and the next command got executed.

Thank you


All times are GMT -5. The time now is 07:46 PM.