Removing line from executing script
Developing a script which leaves data in the script which runs the command to remove and write a line.
Done this to scripts b4 but am drawing a blank on removal and get an error. Code:
#!/bin/sh Couldn't find any examples with my search query so needing help. BTW have use echo statements to validate variables and output. |
You are using single quotes instead of double quotes which prevent the shell from expanding the variable:
Code:
sed '${num}d' $0 |
Regrets for not listing the entire script correctly here is with echo statements:
Code:
#!/bin/sh |
Code:
sed "${num}d" $0 > $0 #<<-- FAIL! |
Elaborating on saulgoode's answer (which is correct):
If you use a modern sed version (4+) you can use the -i flag to edit the file in-place: Code:
sed -i "${num}d" $0 Code:
sed "${num}d" $0 > /tmp/${0}.tmp |
that can be solved with a single sed:
sed -i '/^##data/d' <filename> if I understand it well |
druuna & pan64 U have it right! Thanks
|
All times are GMT -5. The time now is 03:47 AM. |