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 https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless --client-secrets src/.config/client_secret_71131800372-dop7miagipbqink2ecnr33so61q3li0t.apps.googleusercontent.com.json

This 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 1


you can use read command to read from STDIN.

read -n NUM -p "Enter the authorization code:" VAR

NUM: 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.

  • No, the line "Enter the authorization code:" comes automatically while executing the command. So I don't need to read it in a variable. I just need to type it in the terminal. Feb 4, 2018 at 10:05
  • you can read input by read VAR without any text. if you don't need the authorization code, why do you want to get the code from the input? Feb 4, 2018 at 11:03

You must log in to answer this question.

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