0

i have written a sed command

sed -i '1 a sometext' filename

his is working in commandline

but in script the changes are not seen when ran from my script

#!/usr/bin/bash

sudo -i
sed -i "1 a sometext" filename
Myjab
  • 924
  • 1
  • 7
  • 22
  • Remove newline after `sudo` command, don't switch from `'` to `"` and use `filename` with full path or relative to root's home directory. – Cyrus Feb 25 '20 at 05:40
  • tried using single quotes also it doesnt work, and why should i remove new line after sudo command – Myjab Feb 25 '20 at 05:42
  • It should be `sudo sed -i "1 a sometext" filename` (and this is arguably what you should use interactively as well). The duplicate explains why it doesn't and can't work the way you tried it – that other guy Feb 25 '20 at 06:22
  • i used double wuoets also my commands after sudois not working not sure why – Myjab Feb 25 '20 at 06:29
  • Try `sudo -e file.txt` I'm not sudoer so that's all I can help. – Jetchisel Feb 25 '20 at 06:32

0 Answers0