I have a command line application which requires a user input:


# something happens here.....
# something happens here too.....

Enter secret pass phrase:

I want to call it from a terminal and pass a secret pass phrase to it right away, without having to enter it manually. How can I do that? I've tried this but it didn't work and I still was asked to provide secret pass phrase:

./some_application my_secret_pass_phrase
  • use expect linux.die.net/man/1/expect – Ipor Sircer Nov 22 '16 at 10:50
  • You should know that your "secret pass phrase" that you pass as a command line argument will be saved in your shell history, will be visible in the process table while your application is running, and thus won't be secret anymore. – Wildcard Nov 22 '16 at 10:50
  • 2
    How did you try it exactly? What language is your application written in? Did you try googling for "commandline arguments language X" where "language X" is whatever you used to write your application? – terdon Nov 22 '16 at 10:50
  • STDIN is not the same as command-line arguments. You're confusing the two - you're trying to pass off a command-line argument as STDIN, which won't work. Instead of "command line user input" (which will come back as command-line arguments), try searching for something like "pass argument to STDIN". – ArtOfCode Nov 22 '16 at 12:45
  • 1
    This smells like an XY problem -- what are you actually trying to do? What is "some application"? – glenn jackman Nov 22 '16 at 20:20

You can do:

printf '%s\n' 'password' | ./some_program

Or use expect, as Ipor Sircer advised in a comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.