LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

The "sed" command doesn't need quotes

Posted 09-15-2017 at 03:20 PM by the dsc
Updated 12-02-2017 at 12:24 AM by the dsc

You may have some trouble when trying to make sed replacements along the lines of:

sed 's|$originalpath|$otherpath/$filename|'

If the variables contain things like the "-" character, or some other special characters, some of the sed commands may be terminated before they should, in error, as it's taking part of the variable as sed commands, rather than parameters. Something like that. Then the variables would ideally be quoted, but with the outermost quotes, it's perhaps impossible or kind of confusing/insane.

But you can use something like:

sed s}"$originalpath"}"$otherpath"/"$filename"}

No need for the outer quotes!

The double quotes are needed for the strings to be understood as strings, and their content used, rather than literally their names, I guess.

"}" is just what I though is perhaps the most unlikely character to be in a file or directory name.

EDIT: It's perhaps not the best choice as the ideal string usage is "${STRING}" even if you're not using it to the fullest extent, like an indexed array. Using that way will preserve multiple spaces in strings, which would otherwise be converted to a single space, messing up with stuff like folders or files that for some odd and arguable reason have multiple spaces. Maybe a question mark would be preferable, it's not just as unlikely in a file name, but rather uncommon, I suppose.


But the "pipe" character as a replacement for the "correct" slash no longer works, as it's interpreted as a pipe. But "plus" works without that problem, and without all the crazy escaping of slashes


As always, it may have some dangerous implications, either technical or political.
Posted in Uncategorized
Views 206 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 04:03 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration