How to pass the value of a variable to the stdin of a command?

后端 未结 9 564
無奈伤痛
無奈伤痛 2020-11-27 14:44

I\'m writing a shell script that should be somewhat secure i.e. does not pass secure data through parameters of commands and preferably does not use temporary files. How can

9条回答
  •  感情败类
    2020-11-27 14:49

    As per Martin's answer, there is a bash feature called Here Strings (which itself is a variant of the more widely supported Here Documents feature).

    http://www.gnu.org/software/bash/manual/bashref.html#Here-Strings

    3.6.7 Here Strings

    A variant of here documents, the format is:

    <<< word
    

    The word is expanded and supplied to the command on its standard input.

    Note that Here Strings would appear to be bash-only, so, for improved portability, you'd probably be better off with the original Here Documents feature, as per PoltoS's answer:

    ( cat <

    Or, a simpler variant of the above:

    (cmd <

    You can omit ( and ), unless you want to have this redirected further into other commands.

提交回复
热议问题