0

I am trying to write a shell script that prompts the user for 3 case-sensitive arguments

username password url

and then take those parameters and calls a python script i.e.: "python streamcount.py username:password -g "url"

I'm starting someplace so I understand how to ask for the parameters but then the output is in the terminal, I am not sure how to proceed to the next step.

3
  • 2
    Wouldn't it be easier to modify the python script to ask for them instead? Also, please show us what you have so far so we don't waste your time with solutions you have already tried. And are you 100% sure you really want to prompt the user for this and not have the script simply take arguments at launch time so you can easily re-run it and avoid typos? Any security issues are moot if you still run the python script with a plain text password anyway.
    – terdon
    Nov 10, 2022 at 19:16
  • I don't see a question here. Can you show your code? Nov 11, 2022 at 14:56
  • Thank you for this, thinking outside the box. I don't own the code of the python script from a public github repo, my intentions with a shell or now considering python script are to simplify the execution Nov 15, 2022 at 16:38

1 Answer 1

2

Based on the information provided, this script should do what you require.

#!/bin/bash

IFS= read -rp $'Enter username\n' username
IFS= read -rsp $'Enter password\n' password
IFS= read -rp $'Enter URL\n' url

python streamcount.py "$username:$password" -g "$url"

The read command prompts the user for input. Using read -s will not echo what the user types which is useful for passwords. All of this could also be done in your Python script.

Remember passing passwords on the command line is a bad idea though as command line arguments are public knowledge within a system. Passing them via environment variables would be a better idea.

1
  • Thank you, I will give it a try. Appreciate the help and guidance Nov 15, 2022 at 16:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .