Question

I'm trying to pass sensitive data to stdin using bash script. I was wondering if I can use

echo "This is verysecretmessage" | IamAwaitingStdin

I thought that since echo is /bin/bash built-in it should not show up in ps or anywhere else, is that correct?

If not, and for example, this will work instead of the solution above

IamAwaitingStdin <<EOF
This is verysecretmessage
EOF

Then how can I use <<EOF bla bla EOF syntax in bash script when encapsulating it with ()? What is the syntax?

I guess this one is not correct since bash is one-liner

$(IamAwaitingStdin << EOF
This is verysecretmessage
EOF)

Thanks!

Was it helpful?

Solution

  1. You are correct that an echo does not create a separate process. The new process's name will come from the other side of the pipe.

  2. Your example of $(...) with a here-document will work fine - most bash constructs can span multiple lines, even though they normally don't. (At most you might need to escape some embedded newlines with \, but within $(...) even that's not necessary.)

  3. You can also use a herestring instead of a heredoc:

    IamAwaitingStdin <<<"This is verysecretmessage" 
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top