LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-24-2020, 06:50 PM   #31
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,572

Rep: Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874

Quote:
Originally Posted by vincix View Post
But if I wanted to use regex for matching the pattern and then substitute it with a literal string, like the sub command does, then all of a sudden I have a problem, in that I yet again have to be careful about what the variable contains, right?
Not necessarily:

Code:
awk -v a="${var}" -v b="${var2}" '{
  while(i=match($0,a))
    $0=substr($0,1,i-1) b substr($0,i+RLENGTH)
  print $0
}' file.txt
 
1 members found this post helpful.
Old 05-25-2020, 05:31 AM   #32
boughtonp
Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 366

Rep: Reputation: 236Reputation: 236Reputation: 236
Quote:
Originally Posted by vincix View Post
I wanted to restrict the thread only to this particular problem without giving the bigger context, but now the context has become much more relevant.
It usually does, and should always be mentioned so people who know the answer to your real problem can go straight to providing the simpler solution that everyone else is already using, instead of either reinventing the wheel or using an ugly hack.


Quote:
The point was to do something somewhat intentionally dumb, that is to say, to change an existing docker-entrypoint from an official docker image (of php-apache) through an additional Dockerfile, where I'd run the sed commands.
The here document would have been a great solution under normal circumstances, and it hadn't occurred to me anyway, but unfortunately it doesn't work in Dockerfile

What I did eventually (which I find much more sensible) was to actually copy only the entrypoint from github, add the sed lines that would replace the php configuration settings, and then copy it into the new image, ensuring, of course, that it has execution permissions (being an entrypoint).
I haven't needed to use Docker yet, so that doesn't make complete sense to me, but it sounds like you want to change the password in a config file, which seems a sufficiently common problem to have a common solution.

How does everyone else using Docker solve it?

What are you doing differently that stops you using their solution?

 
Old 05-25-2020, 12:33 PM   #33
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,149

Original Poster
Rep: Reputation: 85
Well, if you're not familiar with docker it's a little bit harder to explain, I guess, but the solution I've chosen, given that I don't have other orchestration tools (like swarm or kubernetes, which offer so called config files that can be dynamically mounted into the container and being used as such even after you've built the containers), should be the right one in this context. It's just a sed replacement based on environmental variables - this is rather common.

What was weird about what I was trying to do (I'd have stuck with it only if the solution had turned out to be much easier, or maybe not even then), was changing an existing entrypoint (which is just a bash script running every time the container starts), which had already been built in the container image, by adding a few sed lines before the last line. Yeah, I don't think people do that. So that's why I simply copied the whole entrypoint, adjusted to my liking, and made it part of the build (using a Dockerfile of my own - meaning adding another container layer in the image).

I hope it made a little bit of sense


As far as the context is concerned, sure, I agree 100%, I just thought this time I could get away with it

@ntubski, thanks for the answer!
 
Old 05-26-2020, 01:36 AM   #34
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 14,663

Rep: Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777Reputation: 4777
Quote:
Originally Posted by vincix View Post
Well, if you're not familiar with docker it's a little bit harder to explain, I guess, but the solution I've chosen, given that I don't have other orchestration tools (like swarm or kubernetes, which offer so called config files that can be dynamically mounted into the container and being used as such even after you've built the containers), should be the right one in this context. It's just a sed replacement based on environmental variables - this is rather common.
That can be made with docker too. You can "mount" even a simple file into the docker image. Also you can pass environment variables to the docker image. But obviously it all depends on the details....
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Difference between echo of file within double quotes and without double quotes ankitpandey Programming 2 01-11-2013 09:02 AM
translate value from single quotes to double quotes venkateshrupineni Linux - Newbie 2 06-14-2012 03:03 PM
Double Quotes Inside Double Quotes youarefunny Programming 6 06-09-2010 10:21 PM
Problems with quotes and double quotes Andruha Slackware 6 01-02-2010 04:44 PM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 11:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:08 PM.

Main Menu
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