Tip : jq -r to get raw value instead of quoted strings

I just fixed up my example script that invoked mysql with credentials. It was getting the username and password out of the item via jq which returned quoted strings. This caused issues that I didn't anticipate in the mysql invocation. By using -r it works as expected.

Here's my actual working example:

#!/bin/bash
S=$(./op login agilebits) &&
D=$(./op item $S "MySQL localdatabase") &&
USERNAME=$(echo $D | jq -r '.fields[] | select(.designation=="username").value') &&
PASSWORD=$(echo $D | jq -r '.fields[] | select(.designation=="password").value') &&
mysql --host=b5local.com --port=3306 -u $USERNAME --password=$PASSWORD --database=b5

Comments

  • AGAlumB
    AGAlumB
    1Password Alumni

    @rickfillion: Who is your target audience? HAL9000? ;)

  • @brenty : people who are comfortable with shell scripting.

  • AGAlumB
    AGAlumB
    1Password Alumni

    <3

  • DanielP
    DanielP
    1Password Alumni

    @rickfillion Do we have a place where we store some documentation about this, or are we just using this forum section for now? I would love to play around with this a little bit if I had some more information :)

  • @DanielP : no documentation is ready yet beyond the help that the CLI app provides itself. This forum category is private an only available to us AgileBits employees and the external people who have been given early access to the CLI app.

  • DanielP
    DanielP
    1Password Alumni

    Sounds good @rickfillion, when and if you need some help with that, I'd be happy to help out with the docs.

This discussion has been closed.