0

Trying to append a import file path to files, doesn't work, and here is a simple repro:

I tried haha="a/b/c/d/e"; sed -i '1s/^/"'$haha'"\n/' /tmp/processing.sh; , it doesn't work, and gave me this error: sed: -e expression #1, char 9: unknown option to `s'

Can anyone help with this?

  • 1
    Change the `/` to something else like a pipe `|` , e.g. `sed ... 's|...|...|'` – Jetchisel Jul 27 '21 at 20:38
  • doesn't work for me, how should I change sed -i '1s/^/"'$haha'"\n/'? – user3259711 Jul 27 '21 at 20:52
  • 1
    If you can't change the `/` to a pipe `|` from your `sed` syntax then sorry I can't help. I already have a sample code for you. Just replace the `/` to a pipe `|`. Also shell variables does not expand in single quotes. – Jetchisel Jul 27 '21 at 20:53
  • 2
    One doesn't particularly need `sed` for this at all. `{ echo "new first line"; cat file.txt; } >"file.txt.$$" && mv -- "file.txt.$$" file.txt` – Charles Duffy Jul 27 '21 at 21:00
  • Or `printf "%s\n" 1i "$haha" . w | ed -s /tmp/processing.sh` – Shawn Jul 27 '21 at 22:07

0 Answers0