AnswerBun.com

Feed script variable to command that prompts for user input

Unix & Linux Asked by Vishnu Sajeevan on December 15, 2020

I have a shellscript ABCD.sh and it will have a command to upload a file onto server which will prompt for username and password.

Instead of providing username and password there, I would like to pass the username and password as an external argument only, how it is possible?

username =$1
password=$2
pushcommand

The pushcommand will ask to enter username and password; the shellscript should automatically take it from $1 and $2.

One Answer

If pushcommand simply reads first username and then password from standard input, separated by newline, you can do the following:

echo "$usernamen$password" | pushcommand

The "echo" call here will output the username and password variables on separate lines.
The "|" means "take the output of the command on the left, and feed it as input to the command on the right". This construct is called a "pipe" in shell scripts.

For scripting more complex interactions, I'd recommend looking at expect or possibly kermit. To get help with expect or kermit, you'd have to post an example on how an interactive use of pushcommand actually looks like, e.g. what prompts it displays and so on.

Answered by rosarote elfe on December 15, 2020

Add your own answers!

Related Questions

Why I cannot see filesystem in result of df -h?

0  Asked on October 31, 2021 by qmski

 

Postfix cannot start but dovecot is ok

1  Asked on October 31, 2021 by phan

     

Logging in with ‘su’ without entering a password

2  Asked on October 31, 2021 by user3561602

     

Ranger – open_with without suspending

3  Asked on October 31, 2021 by tigerjack

       

CentOS 8: Modular dependency problems

3  Asked on October 30, 2021 by aditya-k

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir