Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm using this command to update some PHP scripts and I need to find a pattern and replace it with a $var. Sed doesn't seem to want to work with the $ sign as it does everything else I expect it to except insert $var.
WARNING: Do not use any copied code untill you are quite sure what it is doing.
One more thing, Please show us some effort of your own instead of copying code and asking us to correct it.
The grep will list all files having the someword in your curent directory unless you exclude, so any mistake of yours can give you a bad day at work.
I would prefer wrapping the variables
Code:
${variable}
------------
$var,someword
would be treated as a variable name unless you separate the variable to be identified by the nmae you gave it.
Last edited by SAbhi; 12-10-2014 at 11:36 PM.
Reason: typo correction
WARNING: Do not use any copied code untill you are quite sure what it is doing.
One more thing, Please show us some effort of your own instead of copying code and asking us to correct it.
The grep will list all files having the someword in your curent directory unless you exclude, so any mistake of yours can give you a bad day at work.
I would prefer wrapping the variables
Code:
${variable}
------------
$var,someword
would be treated as a variable name unless you separate the variable to be identified by the nmae you gave it.
I apologize but I do not administer linux systems often. This is a random happenstance that comes up from time to time. Isn't the point of forums to get help? Perhaps you don't realize how I like to learn. I need examples to build a bit of confidence and then I go from there. Linux system administration to me, is a very daunting task. I'm always intimidated by it.
Would you mind explaining how I can wrap "$var" I tried with single quotes and it didn't work.
I apologize but I do not administer linux systems often. This is a random happenstance that comes up from time to time. Isn't the point of forums to get help? Perhaps you don't realize how I like to learn. I need examples to build a bit of confidence and then I go from there. Linux system administration to me, is a very daunting task. I'm always intimidated by it.
Would you mind explaining how I can wrap "$var" I tried with single quotes and it didn't work.
He means to "wrap" it in the curlybraces as shown...
Code:
$variable
...when wrapped becomes...
${variable}
... where the variable name goes inside the {...}.
UPDATE ****
But this is really only relevant if it goes into a shell script - potentially a problem inside a PHP script which is your actual target! So see next reply...
In the context of the resultant php file the wrapping is potentially irrelevant or even an error, so do it as shown above.
As cautioned by others - test this first on an example file - do not copy, paste and use on your live files!
If you could post a snippet of an actual PHP file that you want to change, including an example of exactly what you want it changed to, we could give you a working example much more easily.
In the context of the resultant php file the wrapping is potentially irrelevant or even an error, so do it as shown above.
As cautioned by others - test this first on an example file - do not copy, paste and use on your live files!
If you could post a snippet of an actual PHP file that you want to change, including an example of exactly what you want it changed to, we could give you a working example much more easily.
Ahh yes, I knew there would be a way to escape characters somehow. This is it. Thank you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.