Score:0

sed: -e expression #1, char 113: unknown command: `['

gh flag

I was wondering why isn't this code working, it is simple but for some reason it's not working.

WIREGUARD_TEMP_NEW_CLIENT_INFO="# ef37a62148810e97daa4deb88fa7f8add6532c39d2feb56d712a0ab1e8f5fd13ec52cfb1751ad3812e21f33a1e0508f14b7d start
[Peer]
PublicKey = L5SCXFRI4Mhyo1nKTjs5d64CSGd36ehC8MD8jg2FbEM=
PresharedKey = 3sejb0srnD3ZHy4I3rydIqy6CPXEHwXWeoX2Yu/2msU=
AllowedIPs = 10.0.0.4/32,fd00:00:00::4/128
# ef37a62148810e97daa4deb88fa7f8add6532c39d2feb56d712a0ab1e8f5fd13ec52cfb1751ad3812e21f33a1e0508f14b7d end"

sed -i "$((6 * 4 - 6 + 11))i${WIREGUARD_TEMP_NEW_CLIENT_INFO}" /etc/wireguard/wg0.conf

The error I am getting is

sed: -e expression #1, char 113: unknown command: `['

What is the code doing?

It's just going to a given line number and adding the content to the given live number.

Davidw avatar
in flag
That's the kind of response that suggests something is missing in the command line.
gh flag
Like, what could it be?
Score:1
bd flag

Your second argument to sed, "$((6 * 4 - 6 + 11))i${WIREGUARD_TEMP_NEW_CLIENT_INFO}" expands to the multiline string:

29i# ef37a62148810e97daa4deb88fa7f8add6532c39d2feb56d712a0ab1e8f5fd13ec52cfb1751ad3812e21f33a1e0508f14b7d start
[Peer]
PublicKey = L5SCXFRI4Mhyo1nKTjs5d64CSGd36ehC8MD8jg2FbEM=
PresharedKey = 3sejb0srnD3ZHy4I3rydIqy6CPXEHwXWeoX2Yu/2msU=
AllowedIPs = 10.0.0.4/32,fd00:00:00::4/128
# ef37a62148810e97daa4deb88fa7f8add6532c39d2feb56d712a0ab1e8f5fd13ec52cfb1751ad3812e21f33a1e0508f14b7d end

The sed command i inserts the string following it on the same line. The next line is interpreted as a new command by sed. Since [Peer] isn't a valid sed command, it emits the error message you are seeing.

gh flag
So how would i write the data than?
gh flag
```sed -i "1i\apple\nbees" file```
Score:0
cn flag

This is the code that someone needs to use if they run into the same issue.

#!/bin/bash

TEMP_VALUE="# ef37a62148810e97daa4deb88fa7f8add6532c39d2feb56d712a0ab1e8f5fd13ec52cfb1751ad3812e21f33a1e0508f14b7d start\n[Peer]\nPublicKey = L5SCXFRI4Mhyo1nKTjs5d64CSGd36ehC8MD8jg2FbEM=\nPresharedKey = 3sejb0srnD3ZHy4I3rydIqy6CPXEHwXWeoX2Yu/2msU=\nAllowedIPs = 10.0.0.4/32,fd00:00:00::4/128\n# ef37a62148810e97daa4deb88fa7f8add6532c39d2feb56d712a0ab1e8f5fd13ec52cfb1751ad3812e21f33a1e0508f14b7d end"
sed -i $((1 + 1))i"${TEMP_VALUE}" file
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.