reitermarkus reitermarkus - 1 year ago 86
Bash Question

Terminal shell: How to use echo instead of a text file as command-line arguments

I have a command line utility which needs a text file (to format the output) as argument. I only need the pure value and no formatting, so I'd like to have a one-line script to get the value.

The text file

only contains:


Here's an example of my utility:

vclient -h -t template.file -g getTempKist

What I would like is something like this:

vclient -h -t $(echo '\$1') -g getTempKist

Does anyone know how to use the result of an
(or maybe an alternative) instead of an external text file?

I hope someone can help.


Answer Source

You can try two things:

First, you can probably use stdin for the input like this:

echo '$1' | vclient -h -t - -g getTempKist

Some tools support the special value - for filename arguments where - stands for stdin. However this depends on the implementation of the command.

Second thing you can use if your shell (like bash or zsh) supports this is to use process substitution:

vclient -h -t <(echo '$1') -g getTempKist
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download