1

I have a simple bash script named text.sh which looks like this:

#!/bin/bash
read username
read password
echo "script attempted with $username $password"

I want to call it using something like this:

[root@ip-192.168.0.0 root]# ./test.sh bing s3cr3t

And have it echo back:

script attempted with bing s3cr3t

I can use <<< to get bing to print, but not both. I'm sure this is simple, but my Google-fu is failing since I don't know what keywords to search for.

2

What you want is to access the command-line arguments, not to read from standard input. A script with the proper method:

#!/bin/bash
username="$1"
password="$2"
echo "script attempted with $username $password"

The special variables $1, $2 &c. contain the first, second &c. arguments passed on the running command line. More information available here, among many other places.

  • 1
    I remembered it was something simple, but couldn't remember this, thank you! I'll accept in 10 min, when it allows me to. – Bing Nov 12 '15 at 18:41

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.