Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
The following script perhaps uses awk and system commands
Write a simple shell script to do the following.
a) Read a set of commands specified in a file cmd.txt
b) Execute them one by one, save the output.
c) After all the command executions are complete, print the outputs properly formatted to show which output belongs to which command. Also show the return status of each command.Vivek

I don't think you'll get much help with home work without at least showing some effort. What do you have so far?

I am able to proceed this far
grep "" cmd.txt | sh -v > output
This reads a set of commands specified in a file cmd.txt, Executes them one by one, saves the output.
Vivek

Why don't you read the file a line at a time and execute each command redirecting the output to a file:
#!/bin/ksh
while read cmds
do
eval "$cmds >> output.file"
done < mycmds.txt

I'm not the original poster of this question. But I do not quite understand the last sollution. If you have the time can you explain it.
Thanks in advance

Hi:
Be glad to. All of the valid unix commands are listed, one per line, in file mycmds.txt.
The while loop reads mycmds.txt one line at a time. I build a command string from each line of input and redirect the ouput appending it to output.file with >>.The command string is an argument to the eval command. When the eval command executes, the argument is treated as input to the shell, i.e. ksh in this case, and the resulting commands as defined in the string, execute.
Regards,
Nails

To find the return status of each command - $?
www.finepick.com the 100% FREE Online Classifieds (Chennai)Jc

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |