title: Merge bash command(s)/simplification of a long command in bash
body: <p>Hi I am making one script for which I would like it, that through one command it would be possible to make a more complex command or function. The problem is that I have three docker containers which have the same name but only the digit changes. And just the docker container has one entry in the logs and that is just the right <code>Cloudflared</code> URL, I need to get it through that <em>sub-command</em> or <em>function</em> more than <strong>1 times</strong>. Because I have <strong>three docker containers</strong> and <strong>each would have a different url</strong> from the <strong><code>logs</code></strong>.</p>
  <p>I know that via classic way it goes! Only problem is that if I repeat the same commands it creates a little mess in the script (at least that's how I feel).</p>
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  function test {
      docker_container_proxy_name=&quot;cloudflared&quot;
      real_domain_of_cloudflared=&quot;https://([a-z0-9]{1,60})(-[a-z0-9]{1,60})(-[a-z0-9]{1,60})(-[a-z0-9]{1,60}).trycloudflare.com&quot;
      docker_container_1_uri_outside=&quot;$(docker logs ${docker_container_proxy_name}1 2&gt;&amp;1 | grep -Eo $real_domain_of_cloudflared | tail -n 1)&quot;
      docker_container_2_uri_outside=&quot;$(docker logs ${docker_container_proxy_name}2 2&gt;&amp;1 | grep -Eo $real_domain_of_cloudflared | tail -n 1)&quot;
      docker_container_3_uri_outside=&quot;$(docker logs ${docker_container_proxy_name}3 2&gt;&amp;1 | grep -Eo $real_domain_of_cloudflared | tail -n 1)&quot;
  }
  test
  </code></pre>
  <p>Is there any way through which I can <strong>simplify</strong> it like the whole long command, but only the docker container <strong>digit</strong> changes. Into like this (<em>more cleaner in my eye</em>):</p>
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  function test {
      docker_container_proxy_name=&quot;cloudflared&quot;
      real_domain_of_cloudflared=&quot;https://([a-z0-9]{1,60})(-[a-z0-9]{1,60})(-[a-z0-9]{1,60})(-[a-z0-9]{1,60}).trycloudflare.com&quot;
      command=&quot;$(docker logs ${docker_container_proxy_name} 2&gt;&amp;1 | grep -Eo $real_domain_of_cloudflared | tail -n 1)&quot;
      docker_container_1_uri_outside=&quot;${command}1&quot;
      docker_container_2_uri_outside=&quot;${command}2&quot;
      docker_container_3_uri_outside=&quot;${command}3&quot;
  }
  test
  </code></pre>
  <p>I would be glad for an answer.
  Maybe a similar question already exists, but I admit I didn't look for it and went straight to write my question, and I apologize that maybe this will be a similar post.</p>
  <p>Docker containers:</p>
  <pre class="lang-sh prettyprint-override"><code>$ docker container ps | grep &quot;cloudflared&quot;
  &lt;id_of_container&gt; cloudflare/cloudflared:2022.4.1-amd64 &quot;cloudflared --no-au…&quot; 11 days ago Up 2 days cloudflared3
  &lt;id_of_container&gt; cloudflare/cloudflared:2022.4.1-amd64 &quot;cloudflared --no-au…&quot; 11 days ago Up 2 days cloudflared2
  &lt;id_of_container&gt; cloudflare/cloudflared:2022.4.1-amd64 &quot;cloudflared --no-au…&quot; 11 days ago Up 2 days cloudflared1
  
  #1 for XFCE_noVNC
  #2 for filebrowser
  #3 for code-server
  #i want this services in my &quot;pocket/everywhere&quot; without my public ipv4.
  </code></pre>