Bashing trouble in MSYS: The following simple function should delete all lines that match user-input string $kwd.
function delnote () {
read kwd
sed -e "/$kwd/d" -i ~/notes.txt
}
Instead, I keep getting “sed -e expression #1, char 0: no previous regular expression” errors. Why?
I’m new to both bash and sed (and MSYS), so I’m not sure whether this is an issue of passing variables to sed or using quotes the wrong way (I’ve effortlessly tried replacing "" with '' in many variations). I tried using the function provided here instead of my own, but still got the same error.
In case this is an issue of misplacing quotes, then what’s the difference between how sed and grep handle user input in bash? (As opposed to sed, using '"$*"' in a grep function does work.)
Thanks for any help and explanations!
Okay, I yet seemed to mess something up when copying the solution linked above. Now it works, like this:
As a non-coder and n00b, I’d still appreciate any explanations as to what was wrong with my initial version, though. Plus, why does
echoseem to fix the issue here? Thanks.