Как преобразовать '\t' и '\n' в выводе терминала json во что-то полезное?

Здесь есть два возможных подхода, в зависимости от ваших требований. Если вы не хотите запрашивать пароль при активации службы, используйте директиву EnvironmentFile. Изman systemd.exec:

Similar to Environment= but reads the environment variables from a text file. The text file should contain new-line-separated variable assignments.

Если вы действительно хотите получать подсказки, вы должны использовать одну из директив systemd-ask-password. Изman systemd-ask-password:

systemd-ask-password may be used to query a system password or passphrase from the user, using a question message specified on the command line. When run from a TTY it will query a password on the TTY and print it to standard output. When run with no TTY or with --no-tty it will use the system-wide query mechanism, which allows active users to respond via several agents

1
01.10.2019, 00:57
2 ответа

jqпо умолчанию выводит закодированные строки JSON -.

Если вы хотите необработанную строку message, используйте -rили--raw-output:

jq -r.message file.json

(если file.json— документ JSON, который вы показываете ). Это расширит вкладки и новые строки в этой конкретной строке.

3
27.01.2020, 23:17

Разбор JSON в bash никогда не рекомендуется, но....

если можно помассировать линию:

    "message": "newline\n\nword\tword\tword", 

стать:

X_message="newline\n\nword\tword\tword"

тогда можно:

$ echo -e "$X_message"
newline

word    word    word
1
27.01.2020, 23:17

Теги

Похожие вопросы