Signing back into the Community for the first time? You'll need to reset your password to access your account. Find out more.
Forum Discussion
XIII
4 years agoTrusted Contributor
[46] How can I use a newline character in a field value?
In the past I created some multi-line fields for SSH keys after reading this tip on this forum.
I now want to update one of those keys using op item edit "K" 'private key=X\nY'
.
However then op item get "K" --fields "private key"
returns this:
X\nY
where I hoped to get
X
Y
(as before)
How can I do this using the (new) CLI?
1Password Version: CLI 2.0.0-beta.11
Extension Version: n/a
OS Version: macOS Big Sur 11.6.2
- XIIITrusted Contributor
Ah, it does work when doing it in a script:
op item edit "K" "private key=-----BEGIN OPENSSH PRIVATE KEY-----
X
Y
-----END OPENSSH PRIVATE KEY-----"
Still would like to know how to do it on the command line though.
- Former Member
Hey XIII, thank you for pointing this out to us!
Indeed, it seems that strings that are passed toop item edit
aren't parsed at all, except for separating the field key from the field value. I am going to open up a bug ticket for this, and discuss it with my team during our next meeting. I will follow up on the thread with the due updates.
Have you noticed such unexpected behaviour in other parts of the CLI too?
Also, do you have any other suggestions, related to howop item edit
should work? Would, for example, being able to pipe input into the command be helpful to you?
Thank you for trying out our CLI. We're looking forward to hearing more of your feedback!!Best,
Horia - XIIITrusted Contributor
Yes, piping would be helpful.
- Former Member
Hey XIII ,
While we look into the issue, I've found a temporary workaround in setting field values to contain newlines via the CLI.
I understand my solution is not ideal as it is quite inconvenient, but it may serve you for the time being while we sort things out.
You can set the values into a temporary variable:
export VALUE_WITH_NEWLINES="A\nb\n3"
And interpolate the variable into the
op item edit
orop item create
commands:op item edit exampeItem "section1.field1[text]=$(echo $VALUE_WITH_NEWLINES)"
By the way, I noticed you wrote "(as before)" in your original post, I am wondering if newlines had worked for you in setting field values in the CLI v1? I ask because I have not been able to do so, for example:
op1 create item login --vault demo --title exampleItem notesPlain="A\nb\n3"
Results in a username field that also contains the raw
\n
chars instead of newlines.I share Horia's sentiment - thank you for the feedback!
- XIIITrusted Contributor
About the "before": I created some SSH "templates" and filled them with multiline text quite some time ago. I'm pretty sure I did that using the CLI (v1), though I can't remember the details...
- Former Member
Hey XIII ,
Gotcha, I think templates would have worked with newlines in v1. I simply tried with the field assignments.
While templates continue to work in v2, the template body is not quite intuitive at the moment as it uses v1 item json body structures, and we are working on improving it!