![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Redirect to a Variable? Or is it cmd cap? | oxoxo | UNIX for Dummies Questions & Answers | 2 | 11-22-2008 08:59 AM |
| Redirect Query o/p to variable | Swapna173 | UNIX for Dummies Questions & Answers | 2 | 08-01-2008 07:48 AM |
| redirect cat to variable | shailesh_arya | Shell Programming and Scripting | 7 | 07-10-2008 05:34 AM |
| Redirect to variable | MrAd | UNIX for Dummies Questions & Answers | 2 | 05-07-2007 05:18 PM |
| please help: how to redirect input into a variable | artur80 | Shell Programming and Scripting | 2 | 11-17-2002 10:18 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi all, I have a selection of files that contain several commands that write to a file and are started as background processes similar to below. Code:
command_to_run_simulator -simulator_arguments > log_file 2>&1 & command_to_run_simulator -simulator_arguments > log_file 2>&1 & command_to_run_simulator -simulator_arguments > log_file 2>&1 & I want to write a wrapper script that will read each file a line at a time, execute that line and store the PID for each line so that after a certain amount of time the processes can be killed. I haven't implemented a full script for this but what I have written is here: Code:
#!/bin/sh while read line do $line # command_to_run_simulator -simulator_arguments > log_file 2>&1 & echo $! done < $1 I was expecting that each line in the file would be read output and run. If I insert the commented line, an exact copy from the original file, it works fine . If I leave the variable in there then I get the following error :Unexpected option '>' It seems that when $line is expanded somehow the meaning of the redirection symbol is lost. Can anyone explain how $line is expanded and why the redirection is lost? As a secondary thing, is there a better way to achieve what I'm trying to do? Please ask if anything isn't clear or I've missed relevant information. On that note, my shell is GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu). Many thanks, Geoff. |
![]() |
| Bookmarks |
| Tags |
| redirection, variable expansion |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|