What is op expect in stdin?

Options
kv3
kv3
Community Member

$ op --version
0.8.0

When I use "op get" in a loop, it looks like it consumes all of my stdin, which breaks the expected behaviour in the loop.
Why is that?

Context setting:

I created two login items as below (printed the title and UUID using jq)
$ op list items | jq '.[] | select(.overview.title | test("XXX")) | .overview.title,.uuid'
"XXX"
"o4rhpeihtfhrvcsfandstpmm5a"
"XXX 1"
"j5ug6csxmbbhpmzza7akxio3ru"

I can read and dump the values in a loop as below:
$ op list items | jq '.[] | select(.overview.title | test("XXX")) | .overview.title,.uuid' |
while read t; read u; do
u=$(echo $u | sed 's/"//g') ;
echo "$t\t\c" ; echo "$u" ;
done
"XXX" o4rhpeihtfhrvcsfandstpmm5a
"XXX 1" j5ug6csxmbbhpmzza7akxio3ru

When I try to process with op, the stdin data is consumed...
$ op list items | jq '.[] | select(.overview.title | test("XXX")) | .overview.title,.uuid' |
while read t; read u; do
u=$(echo $u | sed 's/"//g') ;
echo "$t\t\c" ; echo "$u" ;
op get item $u >/dev/null ;
done
"XXX" o4rhpeihtfhrvcsfandstpmm5a

If I redirect stdin for op, then things get back to normal.
$ op list items | jq '.[] | select(.overview.title | test("XXX")) | .overview.title,.uuid' |
while read t; read u; do
u=$(echo $u | sed 's/"//g') ;
echo "$t\t\c" ; echo "$u" ;
op get item $u >/dev/null </dev/null ;
done
"XXX" o4rhpeihtfhrvcsfandstpmm5a
"XXX 1" j5ug6csxmbbhpmzza7akxio3ru

What is happening here?

Initially I chalked it ot catalina vagaries, but this is universal.

Comments

  • felix_1p
    felix_1p
    1Password Alumni
    Options

    This is actually a feature that we plan to remove, since it prevents us to use stdin for more useful things. At the moment, instead of reading a session token from an environment variable, the token can also be passed on stdin (https://support.1password.com/command-line/#use-with-multiple-accounts).

    But as I said, we plan to remove this functionality and be smarter about when we read from stdin. I ran in the exact same issue in one of our test cases. It's easy to forge that shell script works like that.

  • kv3
    kv3
    Community Member
    Options

    Ah ok, thanks,

    It is still counterintuitive though. By this explanation, I would expect it to consume a line of input, complain about invalid session key. Instead it loops consuming all stdin, I guess trying to attempt to read a valid key.

    BTW, I am not able to parse your last sentence. Could you explain what you mean there?

    THanks

  • Ben
    Options

    @kv3

    I believe @felix_1p forgot a t and instead the sentence should read:

    It's easy to forget that shell script works like that.

    Ben

  • kv3
    kv3
    Community Member
    Options

    doh! yeah, ok that makes sense :-)

  • Ben
    Options

    :+1: :)

    Ben

This discussion has been closed.