I recently had to develop a bash script in order to automate the submission of a job
The job submission script could be run like this
someTextOutput | thatCommand
So 'thatCommand' can be piped input directly.
My issue was that 'someTextOutput' for me needed to be template replaced with user provided inputs. For example I wanted to do this
I discovered the m4 template processor tool, and here was my solution, or close to it. Cool!
Happy scripting!
The job submission script could be run like this
someTextOutput | thatCommand
So 'thatCommand' can be piped input directly.
My issue was that 'someTextOutput' for me needed to be template replaced with user provided inputs. For example I wanted to do this
% aCommand var1 var2This should replace values of tokens in a template file with var1 and var2 and the resulting output should become 'someTextOutput'
I discovered the m4 template processor tool, and here was my solution, or close to it. Cool!
#!/bin/bashI can use this in so many applications, all without having to resort to other tools/scripts when I don't need to.
# some input handling code ...
# now send over template processed output to the target command
cat /tmp/templateFile.txt | m4 -Dvar1="$1" -Dvar2="$2" | thatCommand
Happy scripting!
Comments
Post a Comment