I am working on a script that among other things will delete a line from a file. The line to be deleted is stored in a variable, and constructed from a command line argument. Here’s what I have so far:
#!/bin/sh
repo=$1
devscript=/usr/local/bin/svn-post-commit-update-$repo-dev
livescript=/usr/local/bin/svn-post-commit-update-$repo-live
sudoer="www-data ALL=(root) NOPASSWD: $devscript, $livescript"
sed -i '//$sudoer/ d' /home/bdugan/t.txt
And I am getting the following error:
sed: -e expression #1, char 3: unknown command: `$’
I realize that at this point there is some simple syntax issue that I’ve messed up, but for the life of me I can’t find it. Any ideas?
The key point is that you must use double quotes so the variable gets expanded. Otherwise,
sedsees the dollar sign literally.Also key is that your pattern contains slashes. You must use alternate delimiters:
Choose a delimiter that is unlikely to appear in the string.