I am new to writing bash scripts (and not very good). So it would be great if I can get some explanatory help with my question.
The following is the bash script I have written to provide standard input to ./runnable (executable file) carrying input.aa as argument. I want to record output of this ./runnable input.aa in another file say, output. Any suggestions on how to reframe my code? If there is anything wrong with my script, please drop in suggestions.
#!/bin/bash
./runnable input.aa <<EOF
>2 #input I want runnable to take
>15
>7
>12
>16
>92
>18
EOF
Sure, just change line 3 to
./runnable input.aa >output <<EOF
The >
is the output redirection operator - it sends standard output to the named file.
If you want to capture standard error as well (typically error messages etc.), then use
./runnable input.aa >output 2>errput <<EOF
instead. Or you can get them both intermixed in the same file with
./runnable input.aa >alloutput 2>&1 <<EOF
An addition to David's suggestion is to pipe your command through tee . This allows you to dump the output to a file and see it at the same time (useful for interactive scenarios).
since runnable is expecting inputs. you can not use output redirection before starting here documents .
you will have to do the following to send the output of runnable to a separate file.
#!/bin/bash
OUTFILE=file3.txt
(
./runnable input.aa << EOF
2
4
3
4
3
3
2
EOF
) > $OUTFILE
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.