I have already read a similar question, but there is no solution to my problem.

I want to delete some line in some file I use sed in the script this is the code.

del='echo "'/"$line"/d'"' #it's a AltGr+7 on AZERTY keyboard but for readability of the code I use '
sed -i $del /home/example/fic.txt

I also try:

del='echo "/"$line"/d"'
sed $del /home/example/fic > /home/example/fic

but I have the same error:

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

1 Answer 1


Try this,

del=`echo "/"$line"/d"`
sed $del /home/example/fic > /home/example/fic

In your code, you are single quotes while assigning value to variable del. which will consider as a static string rather than executing it. We can use backticks or $() to execute it.

better way,

sed -i "/$line/d" /home/example/fic
  • -i edit in line.
  • Thank you for your answer, I already note in the comment, I don't know how to add ` in the code and I use ' only for example. I use ` in my script but it doesn't work :) Aug 7, 2019 at 11:56
  • it' s work when I use directly sed "/$line/d" /home/example/fic Thank you :) Aug 7, 2019 at 12:15
  • Now when I call the scrit which contente sed -i "/$line/d" /home/example/fic I Have this error: sed: -e expression #1, char 0: no previous regular expression Aug 7, 2019 at 12:44
  • thank you it's OK know :) Aug 7, 2019 at 12:51
  • 2
    Use $(...) instead of backticks -- easier to see that it's different from single quote. Aug 7, 2019 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.