0

I created a command line interface with Typer to a client for an http server.

This starts an interactive login that displays prompts for username, and then password. If valid, it echoes the authorization token to standard output.

$ snappy login
Username:
Password:

How does one capture the last output in a shell script? I've tried a basic subshell:

token=$(snappy login)

But then token captures Username: Password: <authorization token>, and no text is displayed to standard output.

My current choice:

script -qc 'snappy login'
token=$(tail -1 typescript)
rm typescript

Bottom 13 lines removed because they only contained the token characters:

$ snappy login 2>&1 | hexdump -C
myemail@mail.com
00000000  55 73 65 72 6e 61 6d 65  3a 20 50 61 73 73 77 6f  |Username: Passwo|

00000010  72 64 3a 20 65 79 4a 30  65 58 41 69 4f 69 4a 4b  |rd: eyJ0eXAiOiJK|
Matt Leader
  • 133
  • 1
  • 8

1 Answers1

0

try

token=$(snappy login | cut -d':' -f3)

cut -d':' -f3 <-- Use : as delimiter and print 3rd field

Digvijay S
  • 2,665
  • 1
  • 9
  • 21