I have seen this question:Pause execution and wait for user input , but my problem is different.
I have a Command:
google-oauthlib-tool --scope --save --headless --client-secrets src/.config/client_secret_71131800372-dop7miagipbqink2ecnr33so61q3li0t.apps.googleusercontent.com.jsonThis command provides a link and we get a authorization code on that link. This command waits until we type that authorization code on terminal and after typing the authorization code, further processing happens.
The output of this command as follow:
Please visit this URL to authorize this application:
Enter the authorization code:Now If I write this command in a bash script called script.sh and execute that script, then it doesn't wait for user input of authorization code and further processing happens.
I want that it should wait for authorization code if executing in a bash script.
How can I do it??
1 Answer
you can use read command to read from STDIN.
read -n NUM -p "Enter the authorization code:" VARNUM: number of characters to read from STDIN
VAR: variable to save the input
if you don't know the number of characters or want to read unlimited characters from STDIN, you can remove -n NUM. this causes read command to ended by ENTER and save the result(authorization code) to $VAR.