0

I am writing a shell script which has a bunch of commands, out of which some commands expect user input. For instance, if I want to push my changes to git, I use the command git push, which then asks me for the username and password. A traditional shell script halts for user input when it expects username. What I want to do is, pass this username and password as a command line argument, and the command should pick up that value.

Please note: 1. The above question is not in context to git, I have just used it as an example. I understand that I can always store my credentials in the configuration file specific to git, and then it won't prompt me for the credentials. I only want to know the technique of how such thing is done.

  1. Once again, in regards to the example above, security is not a concern. Currently, I am not concerned about passing the password as clear text from command line.

I tried to google it, but didn't get satisfactory results. Any ideas on this will be helpful.

ATP
  • 832
  • 1
  • 15
  • 29
  • What your talking about is using [Positional Parameters](http://linuxcommand.org/lc3_wss0120.php) and a Google search for bash positional parameters or search for passing arguments to shell script. – user3439894 Feb 01 '15 at 01:33

2 Answers2

1

You need to use the "expect" command to send password.

Refer this answer using expect in bash script

Community
  • 1
  • 1
vijayalakshmi d
  • 686
  • 5
  • 8
0

Command name parameters in shell are referenced by $n where n is the number of parameter starting with 0 which is the name of the script. For instance the following script:

#!/bin/bash
echo $0 #name of the script
echo $1 #the first parameter
echo $2 #the second parameter

will print name of the program and parameters

user987339
  • 10,519
  • 8
  • 40
  • 45