Skip to content

Save multiline value in Etcd from CLI

Posted on:November 5, 2022 (2 min read)

Etcd is a distributed consistent key-value storage similar to ZooKeeper and Consul.

Unfortunately, I couldn’t find a good GUI client, so I usually use the official CLI tool etcdctl. Here is a simple example of how to use it: official doc

It is straightforward and works well, but there is no example of how we can save multiline values (e.g., if we want to save JSON or YAML content). Fortunately, etcdctl documentation in GitHub provides more clarification:

If <value> isn’t given as command line argument, this command tries to read the value from standard input.

A <value> can have multiple lines or spaces but it must be provided with a double-quote as demonstrated below:

So we can use the etcdctl put key_name without providing the value. Then type the value, press Enter to start a new line, and Ctrl-d at the end. Or use etcdctl put key_name < file.json to save the content of the file.json. Another approach is to begin with etcdctl put key_name "first line, input value including new lines, and type a double quote at the end.