Redirect contained in variable not expanded as expected
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.
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:
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).
I'm trying to write a simple script program (C shell). I have a problem redirecting input into a variable. Say I have a variable called J, and there is file called result which contains just some number, say 5. Which command should I use to assign J value 5 from the file result. I tried the... (2 Replies)
how make assign the output of the command (for example: grep "file" "string" ) in a variable ($name)?
i thing how put the result of the command (grep , cut, find ecc) in a variable..
IT's Possible ?? (1 Reply)
how do you redirect stdout into a variable. whenever I try I get an ambiguous redirect error :( I am trying to validate some user input and failing miserably.
cal $MONTH $YEAR | grep -c "$DAY"
if the above is 1 then it is valid if 0 then not valid. I have been trying to redirect the output... (2 Replies)
for the below
grep -i $1 "${logdir}"* | grep -i adding | grep -iv equation | tail -1 | cut -d ':' -f 1
the result of the grep i want to redirect into some variable, i tried to do
veri=grep -i $1 "${logdir}"* | grep -i adding | grep -iv equation | tail -1 | cut -d ':' -f 1
but it is... (2 Replies)
hello
just i saw a really strange for cat
i have file (file1) contains line /home/rajiv/proj1/*.txt
now applied a commonds
DDPATH="$(cat file1)"
echo $DDPATH
it shows all the txt files in that folder like /home/rajiv/proj1/read1.txt /home/rajiv/proj1/read2.txt... (7 Replies)
Hi!
Been working on a script and I've been having a problem. I've finally narrowed it down to this variable I'm setting:
servername=$(awk -v FS=\/ '{ print $7 } blah.txt | sed 's\/./-/g' | awk -v FS=\- '{print $1}')"
This will essentially pare down a line like this:
... (7 Replies)
Hi, I read in this forum that for "https://www.unix.com/shell-programming-scripting/156008-integer-expression-expected-regular-expression.html
thanks! (7 Replies)
I've tried numerous commands, but I am not sure how to use sed in a loop. This is what I have:
VARZ contains CARD_FILE_LIST and it also contains CARD_FILE_LIST2
so
echo "$VARZ"
CARD_FILE_LIST
CARD_FILE_LIST2
I have a file with 60 lines in /tmp/testfile it and I want those lines deleted... (3 Replies)
Hello,
I am trying to print out the first string matching query with grep and I need your help.
My scenario:
Database
John F
4433 Street No 88 CA
Elisabeth Taylor
7733 Street No 26 ON
Jack Nicholson
0133 Green Park No 34 AR
John F 2
9399 Southpark No 02D UT
test.sh... (6 Replies)
I have a little code block (executing on AIX 7.1) that I cannot understand why the NOTFREE=0 does not appear to be assigned even though it goes through that block. This causes a unary operator issue.
#!/bin/bash
PLATFORM="AIX"
NEEDSPC=3000
set -x
if ; then
lsvg | grep -v rootvg | while... (6 Replies)
Discussion started by: port43
6 Replies
LEARN ABOUT HPUX
dtmsglogopenfile
DtMsgLogOpenFile(library call) DtMsgLogOpenFile(library call)
NAME
DtMsgLogOpenFile -- opens a log file
SYNOPSIS
#include <Dt/MsgLog.h>
FILE* DtMsgLogOpenFile(
const char* type,
char** filename_return);
DESCRIPTION
The DtMsgLogOpenFile function calls fopen to open a log file with type open mode. If fopen opens a log file successfully and returns a non-
NULL filename_return, DtMsgLogOpenFile calls malloc to allocate space for filename_return. DtMsgLogOpenFile then copies the log file name
to filename_return.
The caller must use the free function to release the space allocated for filename_return, if it is not NULL. The caller must also close the
file pointer returned by DtMsgLogOpenFile. Use caution in doing this because stderr may be returned.
For a description of the algorithm used to determine the log file to open, see DtMsgLogMessage(3). Note that if a log file cannot be
opened, filename_return will be set to NULL.
ARGUMENTS
type Specifies the file open flag. See fopen(3) for more information.
filename_return
Specifies the variable to receive the returned log file name.
ENVIRONMENT VARIABLES
None.
RESOURCES
None.
ACTIONS /MESSAGES
None.
ERRORS /WARNINGS
None.
EXAMPLES
The following code fragment opens the log file, logs the log file name, closes the file, and frees the space allocated for the file name.
char * log_file;
FILE * fp = DtMsgLogOpenFile ("a+", &log_file);
if (log_file) {
DtMsgLogMessage (argv[0], DtMsgLogInformation,
"The log file name is: %s", log_file);
free (log_file);
}
if (fp && fp != stderr)
fclose (fp);
RETURN VALUE
If DtMsgLogMessage completes successfully, it returns a pointer to the opened log file. If it cannot open a log file, it returns stderr.
FILES
None.
SEE ALSO DtMsgLogMessage(3), DtMsgLogSetHandler(3)
DtMsgLogOpenFile(library call)