Feed script variable to command that prompts for user input

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

I have a shellscript 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

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

Win-Kex Screen Resolution

0  Asked on September 20, 2020


How to call .bashrc function in script

1  Asked on September 14, 2020 by young_souvlaki


recursive statistics on file types in directory?

5  Asked on September 13, 2020 by user394


clamd randomly stops

1  Asked on September 13, 2020 by walter


Authentication fails though the password is correct

0  Asked on September 3, 2020 by rohit-pillai


Cant’t load Windows 10 anymore

1  Asked on August 31, 2020 by j-doe


Change order a icons in system tray widget in KDE?

1  Asked on August 29, 2020 by paddy


rts5139/rtsx_usb borked in 3.15+

2  Asked on August 27, 2020 by roman


ETH0 no address ip with ifconfig

1  Asked on August 24, 2020 by akame14


Kali Linux 2020.2 Wifi Not Working (Realtek)

0  Asked on August 18, 2020 by harriet


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP