I am creating a basic shell script to manipulate a database as a college assignment. However, How many times I try, I can't get the sed command fully correct. The functionality where sed is to be used is this:
$name
is the variable. User will supply the name via the terminal. This name will be looked up in the database and will be deleted if present.
The command I used is this:
sed -i /$name/d <filename>
However, this command only works if the entered value contains no space.
I tried out my solution by using what I could salvage from this
such as sed -i '/$name/d' <filename>
However, to no avail. How to go about this?
Name designation department
– Jun 30 '19 at 11:34sed
is extremely fragile. To take an example, what's stopping a user from deleting everything by entering.
into the value of that variable? How would you prevent disclosing the contents of it when someone enters a value that contains actualsed
code? – Kusalananda Jun 30 '19 at 11:57sed -i "/$name/d" <filename>"
but there are other cases where you have to mix quotes in order to get the shell to do what you want. – NickD Jun 30 '19 at 12:05