Bash evaluation using crazy passwords

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
7
down vote

favorite












I have some code that is loading passwords from AWS SSM and then using them through the script. I am really concerned that some funky password character is going to be used that is going to get interpreted/escaped/munged by bash. The code in question is below. Are there any obvious problems here? Can I improve this so that no password can trip this up?



updateEnvFile() 
sed "s;url=jdbc:mysql://localhost/mysql;url=jdbc:mysql://$host/mysql;"

updateConfig()
local dbs=$1
for db in $dbs; do
local user=$params["/databases/migrate/$env/$db.user"]
local pass=$params["/databases/migrate/$env/$db.password"]
local host=$params["/databases/migrate/$env/$db.host"]
updateEnvFile "$user" "$pass" "$host" > "$bin/../environments/$db.properties"
done







share|improve this question

























    up vote
    7
    down vote

    favorite












    I have some code that is loading passwords from AWS SSM and then using them through the script. I am really concerned that some funky password character is going to be used that is going to get interpreted/escaped/munged by bash. The code in question is below. Are there any obvious problems here? Can I improve this so that no password can trip this up?



    updateEnvFile() 
    sed "s;url=jdbc:mysql://localhost/mysql;url=jdbc:mysql://$host/mysql;"

    updateConfig()
    local dbs=$1
    for db in $dbs; do
    local user=$params["/databases/migrate/$env/$db.user"]
    local pass=$params["/databases/migrate/$env/$db.password"]
    local host=$params["/databases/migrate/$env/$db.host"]
    updateEnvFile "$user" "$pass" "$host" > "$bin/../environments/$db.properties"
    done







    share|improve this question





















      up vote
      7
      down vote

      favorite









      up vote
      7
      down vote

      favorite











      I have some code that is loading passwords from AWS SSM and then using them through the script. I am really concerned that some funky password character is going to be used that is going to get interpreted/escaped/munged by bash. The code in question is below. Are there any obvious problems here? Can I improve this so that no password can trip this up?



      updateEnvFile() 
      sed "s;url=jdbc:mysql://localhost/mysql;url=jdbc:mysql://$host/mysql;"

      updateConfig()
      local dbs=$1
      for db in $dbs; do
      local user=$params["/databases/migrate/$env/$db.user"]
      local pass=$params["/databases/migrate/$env/$db.password"]
      local host=$params["/databases/migrate/$env/$db.host"]
      updateEnvFile "$user" "$pass" "$host" > "$bin/../environments/$db.properties"
      done







      share|improve this question











      I have some code that is loading passwords from AWS SSM and then using them through the script. I am really concerned that some funky password character is going to be used that is going to get interpreted/escaped/munged by bash. The code in question is below. Are there any obvious problems here? Can I improve this so that no password can trip this up?



      updateEnvFile() 
      sed "s;url=jdbc:mysql://localhost/mysql;url=jdbc:mysql://$host/mysql;"

      updateConfig()
      local dbs=$1
      for db in $dbs; do
      local user=$params["/databases/migrate/$env/$db.user"]
      local pass=$params["/databases/migrate/$env/$db.password"]
      local host=$params["/databases/migrate/$env/$db.host"]
      updateEnvFile "$user" "$pass" "$host" > "$bin/../environments/$db.properties"
      done









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jun 21 at 18:59









      Christian Bongiorno

      333110




      333110




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          That cat is entirely unnecessary. Also, multiple pipes to sed are redundant.



          sed by design can take a single long expression and process the data.



          As for your delimiters, I'd suggest using non-printable characters when in sed:



          SED_DELIM=$(echo -en "01")


          and then:



          sed "s$SED_DELIMurl=jdbc:mysql://localhost/mysql$SED_DELIMurl=jdbc:mysql://$host/mysql$SED_DELIM; s$SED_DELIMusername=root$SED_DELIMusername=$user$SED_DELIM; s$SED_DELIMpassword=my-secret-pw$SED_DELIMpassword=$pass$SED_DELIM" $file_name


          Now, that looks quite long. You can evaluate individual expressions:



          sed -e "s$SED_DELIMurl=jdbc:mysql://localhost/mysql$SED_DELIMurl=jdbc:mysql://$host/mysql$SED_DELIM;" 
          -e "s$SED_DELIMusername=root$SED_DELIMusername=$user$SED_DELIM;"
          -e "s$SED_DELIMpassword=my-secret-pw$SED_DELIMpassword=$pass$SED_DELIM"
          $file_name


          I'll go ahead and also use back-references:



          sed -e "s$SED_DELIM(url=jdbc:mysql://)localhost(/mysql)$SED_DELIM1$host2$SED_DELIM;" 
          -e "s$SED_DELIM(username=)root$SED_DELIM1$user$SED_DELIM;"
          -e "s$SED_DELIM(password=)my-secret-pw$SED_DELIM1$pass$SED_DELIM"
          $file_name





          share|improve this answer





















          • It didn't even occur to me that sed might choke on something but a slash is entirely within the realm of password chars that might be chosen. Thanks! I was thinking more like bash and "" doing weird things
            – Christian Bongiorno
            Jun 23 at 2:55







          • 1




            Portable sed command lines have exactly one command per -e argument (writing ; in place of the newline is a common, but not universal, extension to POSIX). Also, given this is Bash, $'01' is simpler than your echo command (but I don't agree with your recommendation not to simply use distinct characters for the delimiters; I like ! or # when / is unsuitable, others choose , - instead, make the variables safe for interpolation, e.g. s!pattern!$replacement//!/!!)
            – Toby Speight
            Jun 25 at 7:45

















          up vote
          2
          down vote













          Do you really pass a single argument with space-separated names to updateConfig like this?:



          updateConfig "db1 db2 db3"


          It would be simpler to let the function accept any number of arguments, then the loop becomes simply



          for db
          do
          #...
          done


          (in "$@" is inferred)




          I'm not a fan of the repetition of /databases/migrate/$env/$db - consider a local variable for that:



          local basepath="/databases/migrate/$env/$db"
          for db; do
          local user=$params["$basepath.user"]
          local pass=$params["$basepath.password"]
          local host=$params["$basepath.host"]
          updateEnvFile "$user" "$pass" "$host" >"$bin/../environments/$db.properties"
          done



          When substituting shell variables using sed s command, be sure to transform the replacement to quote any backslashes or separators in the substitution:



          updateEnvFile() 
          local user=$1//\/\\
          local pass=$2//\/\\
          local host=$3//\/\\

          sed -e "/^url=/s;localhost;$host//;/\;;"
          -e "/^username=/s;=.*;=$user//;/\;;"
          -e "/^password=/s;=.*;=$pass//;/\;;"
          "$bin/../environments/development.properties"



          I've also combined your long pipeline into a singled sed invocation, and simplified each replacement to separate the matching and replacement parts.






          share|improve this answer





















          • The number of databases in question is discovered from the SSM params. So, it looks for anything with $basePath/(db[0-9]+) - literal code for that: echo "$!params[@]" | tr " " "n" | sed 's;.*(db[0-9]).*;1;' | sort| uniq I am going to see about what you have and apply it
            – Christian Bongiorno
            Jun 26 at 1:05










          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f197002%2fbash-evaluation-using-crazy-passwords%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          That cat is entirely unnecessary. Also, multiple pipes to sed are redundant.



          sed by design can take a single long expression and process the data.



          As for your delimiters, I'd suggest using non-printable characters when in sed:



          SED_DELIM=$(echo -en "01")


          and then:



          sed "s$SED_DELIMurl=jdbc:mysql://localhost/mysql$SED_DELIMurl=jdbc:mysql://$host/mysql$SED_DELIM; s$SED_DELIMusername=root$SED_DELIMusername=$user$SED_DELIM; s$SED_DELIMpassword=my-secret-pw$SED_DELIMpassword=$pass$SED_DELIM" $file_name


          Now, that looks quite long. You can evaluate individual expressions:



          sed -e "s$SED_DELIMurl=jdbc:mysql://localhost/mysql$SED_DELIMurl=jdbc:mysql://$host/mysql$SED_DELIM;" 
          -e "s$SED_DELIMusername=root$SED_DELIMusername=$user$SED_DELIM;"
          -e "s$SED_DELIMpassword=my-secret-pw$SED_DELIMpassword=$pass$SED_DELIM"
          $file_name


          I'll go ahead and also use back-references:



          sed -e "s$SED_DELIM(url=jdbc:mysql://)localhost(/mysql)$SED_DELIM1$host2$SED_DELIM;" 
          -e "s$SED_DELIM(username=)root$SED_DELIM1$user$SED_DELIM;"
          -e "s$SED_DELIM(password=)my-secret-pw$SED_DELIM1$pass$SED_DELIM"
          $file_name





          share|improve this answer





















          • It didn't even occur to me that sed might choke on something but a slash is entirely within the realm of password chars that might be chosen. Thanks! I was thinking more like bash and "" doing weird things
            – Christian Bongiorno
            Jun 23 at 2:55







          • 1




            Portable sed command lines have exactly one command per -e argument (writing ; in place of the newline is a common, but not universal, extension to POSIX). Also, given this is Bash, $'01' is simpler than your echo command (but I don't agree with your recommendation not to simply use distinct characters for the delimiters; I like ! or # when / is unsuitable, others choose , - instead, make the variables safe for interpolation, e.g. s!pattern!$replacement//!/!!)
            – Toby Speight
            Jun 25 at 7:45














          up vote
          2
          down vote



          accepted










          That cat is entirely unnecessary. Also, multiple pipes to sed are redundant.



          sed by design can take a single long expression and process the data.



          As for your delimiters, I'd suggest using non-printable characters when in sed:



          SED_DELIM=$(echo -en "01")


          and then:



          sed "s$SED_DELIMurl=jdbc:mysql://localhost/mysql$SED_DELIMurl=jdbc:mysql://$host/mysql$SED_DELIM; s$SED_DELIMusername=root$SED_DELIMusername=$user$SED_DELIM; s$SED_DELIMpassword=my-secret-pw$SED_DELIMpassword=$pass$SED_DELIM" $file_name


          Now, that looks quite long. You can evaluate individual expressions:



          sed -e "s$SED_DELIMurl=jdbc:mysql://localhost/mysql$SED_DELIMurl=jdbc:mysql://$host/mysql$SED_DELIM;" 
          -e "s$SED_DELIMusername=root$SED_DELIMusername=$user$SED_DELIM;"
          -e "s$SED_DELIMpassword=my-secret-pw$SED_DELIMpassword=$pass$SED_DELIM"
          $file_name


          I'll go ahead and also use back-references:



          sed -e "s$SED_DELIM(url=jdbc:mysql://)localhost(/mysql)$SED_DELIM1$host2$SED_DELIM;" 
          -e "s$SED_DELIM(username=)root$SED_DELIM1$user$SED_DELIM;"
          -e "s$SED_DELIM(password=)my-secret-pw$SED_DELIM1$pass$SED_DELIM"
          $file_name





          share|improve this answer





















          • It didn't even occur to me that sed might choke on something but a slash is entirely within the realm of password chars that might be chosen. Thanks! I was thinking more like bash and "" doing weird things
            – Christian Bongiorno
            Jun 23 at 2:55







          • 1




            Portable sed command lines have exactly one command per -e argument (writing ; in place of the newline is a common, but not universal, extension to POSIX). Also, given this is Bash, $'01' is simpler than your echo command (but I don't agree with your recommendation not to simply use distinct characters for the delimiters; I like ! or # when / is unsuitable, others choose , - instead, make the variables safe for interpolation, e.g. s!pattern!$replacement//!/!!)
            – Toby Speight
            Jun 25 at 7:45












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          That cat is entirely unnecessary. Also, multiple pipes to sed are redundant.



          sed by design can take a single long expression and process the data.



          As for your delimiters, I'd suggest using non-printable characters when in sed:



          SED_DELIM=$(echo -en "01")


          and then:



          sed "s$SED_DELIMurl=jdbc:mysql://localhost/mysql$SED_DELIMurl=jdbc:mysql://$host/mysql$SED_DELIM; s$SED_DELIMusername=root$SED_DELIMusername=$user$SED_DELIM; s$SED_DELIMpassword=my-secret-pw$SED_DELIMpassword=$pass$SED_DELIM" $file_name


          Now, that looks quite long. You can evaluate individual expressions:



          sed -e "s$SED_DELIMurl=jdbc:mysql://localhost/mysql$SED_DELIMurl=jdbc:mysql://$host/mysql$SED_DELIM;" 
          -e "s$SED_DELIMusername=root$SED_DELIMusername=$user$SED_DELIM;"
          -e "s$SED_DELIMpassword=my-secret-pw$SED_DELIMpassword=$pass$SED_DELIM"
          $file_name


          I'll go ahead and also use back-references:



          sed -e "s$SED_DELIM(url=jdbc:mysql://)localhost(/mysql)$SED_DELIM1$host2$SED_DELIM;" 
          -e "s$SED_DELIM(username=)root$SED_DELIM1$user$SED_DELIM;"
          -e "s$SED_DELIM(password=)my-secret-pw$SED_DELIM1$pass$SED_DELIM"
          $file_name





          share|improve this answer













          That cat is entirely unnecessary. Also, multiple pipes to sed are redundant.



          sed by design can take a single long expression and process the data.



          As for your delimiters, I'd suggest using non-printable characters when in sed:



          SED_DELIM=$(echo -en "01")


          and then:



          sed "s$SED_DELIMurl=jdbc:mysql://localhost/mysql$SED_DELIMurl=jdbc:mysql://$host/mysql$SED_DELIM; s$SED_DELIMusername=root$SED_DELIMusername=$user$SED_DELIM; s$SED_DELIMpassword=my-secret-pw$SED_DELIMpassword=$pass$SED_DELIM" $file_name


          Now, that looks quite long. You can evaluate individual expressions:



          sed -e "s$SED_DELIMurl=jdbc:mysql://localhost/mysql$SED_DELIMurl=jdbc:mysql://$host/mysql$SED_DELIM;" 
          -e "s$SED_DELIMusername=root$SED_DELIMusername=$user$SED_DELIM;"
          -e "s$SED_DELIMpassword=my-secret-pw$SED_DELIMpassword=$pass$SED_DELIM"
          $file_name


          I'll go ahead and also use back-references:



          sed -e "s$SED_DELIM(url=jdbc:mysql://)localhost(/mysql)$SED_DELIM1$host2$SED_DELIM;" 
          -e "s$SED_DELIM(username=)root$SED_DELIM1$user$SED_DELIM;"
          -e "s$SED_DELIM(password=)my-secret-pw$SED_DELIM1$pass$SED_DELIM"
          $file_name






          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Jun 22 at 14:27









          hjpotter92

          4,89611538




          4,89611538











          • It didn't even occur to me that sed might choke on something but a slash is entirely within the realm of password chars that might be chosen. Thanks! I was thinking more like bash and "" doing weird things
            – Christian Bongiorno
            Jun 23 at 2:55







          • 1




            Portable sed command lines have exactly one command per -e argument (writing ; in place of the newline is a common, but not universal, extension to POSIX). Also, given this is Bash, $'01' is simpler than your echo command (but I don't agree with your recommendation not to simply use distinct characters for the delimiters; I like ! or # when / is unsuitable, others choose , - instead, make the variables safe for interpolation, e.g. s!pattern!$replacement//!/!!)
            – Toby Speight
            Jun 25 at 7:45
















          • It didn't even occur to me that sed might choke on something but a slash is entirely within the realm of password chars that might be chosen. Thanks! I was thinking more like bash and "" doing weird things
            – Christian Bongiorno
            Jun 23 at 2:55







          • 1




            Portable sed command lines have exactly one command per -e argument (writing ; in place of the newline is a common, but not universal, extension to POSIX). Also, given this is Bash, $'01' is simpler than your echo command (but I don't agree with your recommendation not to simply use distinct characters for the delimiters; I like ! or # when / is unsuitable, others choose , - instead, make the variables safe for interpolation, e.g. s!pattern!$replacement//!/!!)
            – Toby Speight
            Jun 25 at 7:45















          It didn't even occur to me that sed might choke on something but a slash is entirely within the realm of password chars that might be chosen. Thanks! I was thinking more like bash and "" doing weird things
          – Christian Bongiorno
          Jun 23 at 2:55





          It didn't even occur to me that sed might choke on something but a slash is entirely within the realm of password chars that might be chosen. Thanks! I was thinking more like bash and "" doing weird things
          – Christian Bongiorno
          Jun 23 at 2:55





          1




          1




          Portable sed command lines have exactly one command per -e argument (writing ; in place of the newline is a common, but not universal, extension to POSIX). Also, given this is Bash, $'01' is simpler than your echo command (but I don't agree with your recommendation not to simply use distinct characters for the delimiters; I like ! or # when / is unsuitable, others choose , - instead, make the variables safe for interpolation, e.g. s!pattern!$replacement//!/!!)
          – Toby Speight
          Jun 25 at 7:45




          Portable sed command lines have exactly one command per -e argument (writing ; in place of the newline is a common, but not universal, extension to POSIX). Also, given this is Bash, $'01' is simpler than your echo command (but I don't agree with your recommendation not to simply use distinct characters for the delimiters; I like ! or # when / is unsuitable, others choose , - instead, make the variables safe for interpolation, e.g. s!pattern!$replacement//!/!!)
          – Toby Speight
          Jun 25 at 7:45












          up vote
          2
          down vote













          Do you really pass a single argument with space-separated names to updateConfig like this?:



          updateConfig "db1 db2 db3"


          It would be simpler to let the function accept any number of arguments, then the loop becomes simply



          for db
          do
          #...
          done


          (in "$@" is inferred)




          I'm not a fan of the repetition of /databases/migrate/$env/$db - consider a local variable for that:



          local basepath="/databases/migrate/$env/$db"
          for db; do
          local user=$params["$basepath.user"]
          local pass=$params["$basepath.password"]
          local host=$params["$basepath.host"]
          updateEnvFile "$user" "$pass" "$host" >"$bin/../environments/$db.properties"
          done



          When substituting shell variables using sed s command, be sure to transform the replacement to quote any backslashes or separators in the substitution:



          updateEnvFile() 
          local user=$1//\/\\
          local pass=$2//\/\\
          local host=$3//\/\\

          sed -e "/^url=/s;localhost;$host//;/\;;"
          -e "/^username=/s;=.*;=$user//;/\;;"
          -e "/^password=/s;=.*;=$pass//;/\;;"
          "$bin/../environments/development.properties"



          I've also combined your long pipeline into a singled sed invocation, and simplified each replacement to separate the matching and replacement parts.






          share|improve this answer





















          • The number of databases in question is discovered from the SSM params. So, it looks for anything with $basePath/(db[0-9]+) - literal code for that: echo "$!params[@]" | tr " " "n" | sed 's;.*(db[0-9]).*;1;' | sort| uniq I am going to see about what you have and apply it
            – Christian Bongiorno
            Jun 26 at 1:05














          up vote
          2
          down vote













          Do you really pass a single argument with space-separated names to updateConfig like this?:



          updateConfig "db1 db2 db3"


          It would be simpler to let the function accept any number of arguments, then the loop becomes simply



          for db
          do
          #...
          done


          (in "$@" is inferred)




          I'm not a fan of the repetition of /databases/migrate/$env/$db - consider a local variable for that:



          local basepath="/databases/migrate/$env/$db"
          for db; do
          local user=$params["$basepath.user"]
          local pass=$params["$basepath.password"]
          local host=$params["$basepath.host"]
          updateEnvFile "$user" "$pass" "$host" >"$bin/../environments/$db.properties"
          done



          When substituting shell variables using sed s command, be sure to transform the replacement to quote any backslashes or separators in the substitution:



          updateEnvFile() 
          local user=$1//\/\\
          local pass=$2//\/\\
          local host=$3//\/\\

          sed -e "/^url=/s;localhost;$host//;/\;;"
          -e "/^username=/s;=.*;=$user//;/\;;"
          -e "/^password=/s;=.*;=$pass//;/\;;"
          "$bin/../environments/development.properties"



          I've also combined your long pipeline into a singled sed invocation, and simplified each replacement to separate the matching and replacement parts.






          share|improve this answer





















          • The number of databases in question is discovered from the SSM params. So, it looks for anything with $basePath/(db[0-9]+) - literal code for that: echo "$!params[@]" | tr " " "n" | sed 's;.*(db[0-9]).*;1;' | sort| uniq I am going to see about what you have and apply it
            – Christian Bongiorno
            Jun 26 at 1:05












          up vote
          2
          down vote










          up vote
          2
          down vote









          Do you really pass a single argument with space-separated names to updateConfig like this?:



          updateConfig "db1 db2 db3"


          It would be simpler to let the function accept any number of arguments, then the loop becomes simply



          for db
          do
          #...
          done


          (in "$@" is inferred)




          I'm not a fan of the repetition of /databases/migrate/$env/$db - consider a local variable for that:



          local basepath="/databases/migrate/$env/$db"
          for db; do
          local user=$params["$basepath.user"]
          local pass=$params["$basepath.password"]
          local host=$params["$basepath.host"]
          updateEnvFile "$user" "$pass" "$host" >"$bin/../environments/$db.properties"
          done



          When substituting shell variables using sed s command, be sure to transform the replacement to quote any backslashes or separators in the substitution:



          updateEnvFile() 
          local user=$1//\/\\
          local pass=$2//\/\\
          local host=$3//\/\\

          sed -e "/^url=/s;localhost;$host//;/\;;"
          -e "/^username=/s;=.*;=$user//;/\;;"
          -e "/^password=/s;=.*;=$pass//;/\;;"
          "$bin/../environments/development.properties"



          I've also combined your long pipeline into a singled sed invocation, and simplified each replacement to separate the matching and replacement parts.






          share|improve this answer













          Do you really pass a single argument with space-separated names to updateConfig like this?:



          updateConfig "db1 db2 db3"


          It would be simpler to let the function accept any number of arguments, then the loop becomes simply



          for db
          do
          #...
          done


          (in "$@" is inferred)




          I'm not a fan of the repetition of /databases/migrate/$env/$db - consider a local variable for that:



          local basepath="/databases/migrate/$env/$db"
          for db; do
          local user=$params["$basepath.user"]
          local pass=$params["$basepath.password"]
          local host=$params["$basepath.host"]
          updateEnvFile "$user" "$pass" "$host" >"$bin/../environments/$db.properties"
          done



          When substituting shell variables using sed s command, be sure to transform the replacement to quote any backslashes or separators in the substitution:



          updateEnvFile() 
          local user=$1//\/\\
          local pass=$2//\/\\
          local host=$3//\/\\

          sed -e "/^url=/s;localhost;$host//;/\;;"
          -e "/^username=/s;=.*;=$user//;/\;;"
          -e "/^password=/s;=.*;=$pass//;/\;;"
          "$bin/../environments/development.properties"



          I've also combined your long pipeline into a singled sed invocation, and simplified each replacement to separate the matching and replacement parts.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Jun 25 at 8:07









          Toby Speight

          17.2k13487




          17.2k13487











          • The number of databases in question is discovered from the SSM params. So, it looks for anything with $basePath/(db[0-9]+) - literal code for that: echo "$!params[@]" | tr " " "n" | sed 's;.*(db[0-9]).*;1;' | sort| uniq I am going to see about what you have and apply it
            – Christian Bongiorno
            Jun 26 at 1:05
















          • The number of databases in question is discovered from the SSM params. So, it looks for anything with $basePath/(db[0-9]+) - literal code for that: echo "$!params[@]" | tr " " "n" | sed 's;.*(db[0-9]).*;1;' | sort| uniq I am going to see about what you have and apply it
            – Christian Bongiorno
            Jun 26 at 1:05















          The number of databases in question is discovered from the SSM params. So, it looks for anything with $basePath/(db[0-9]+) - literal code for that: echo "$!params[@]" | tr " " "n" | sed 's;.*(db[0-9]).*;1;' | sort| uniq I am going to see about what you have and apply it
          – Christian Bongiorno
          Jun 26 at 1:05




          The number of databases in question is discovered from the SSM params. So, it looks for anything with $basePath/(db[0-9]+) - literal code for that: echo "$!params[@]" | tr " " "n" | sed 's;.*(db[0-9]).*;1;' | sort| uniq I am going to see about what you have and apply it
          – Christian Bongiorno
          Jun 26 at 1:05












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f197002%2fbash-evaluation-using-crazy-passwords%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Greedy Best First Search implementation in Rust

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          C++11 CLH Lock Implementation