1

So, I have this piece of a code:

while read line 
        do
            if [ $line = $maddr ] ;
            then
                sed -i '/${maddr}/d' mailinglist
                found=true
                break

            fi
        done < mailinglist

If the read line matches my variable (a string) then delete the whole line.

When it didn't work, I tested it with the flag -x, the pattern is found and it enters the if cycle, it even does the sed command, but the line stays there.

(I create the "mailinglist" file in the script, so I thought, maybe it didn't have write permission, but I checked it and as far as I can tell, I do have the permission - I basically don't change anything about permissions in the script).

I believe the sed command there is right (I have to edit the file and save it right away). Can you help me?

1

Works just fine like this only not with single-quotes but double. I tend to overcomplicate things.

while read line 
        do
            if [ $line = $maddr ] ;
            then
                sed -i "/$maddr/d" mailinglist
                found=true
                break

            fi
        done < mailinglist

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.