<p>So there are commands like <code>docker exec -t</code>, <code>docker-compose exec $CONTAINER /bin/bash</code>, <code>kubectl exec $POD_NAME -it /bin/bash</code> that I use to connect to an instance with a TTY that basically engages an interactive shell instance from my local terminal.</p>

<p>I had build aliases around these or other scripts, but I'm interested in turning these into functions now.</p>

<p>So previously, I might have had:</p>

<pre><code>alias container=`...; docker-compose exec $CONTAINER /bin/bash;` 
</code></pre>

<p>Where <code>...</code> is an arbitrary set of other bash commands necessary for the last statement. This successfully engaged the shell.</p>

<p>Now, I have:</p>

<pre><code>function container {
    ...
    docker-compose exec $CONTAINER /bin/bash
}
</code></pre>

<p>Which seems to hang in a loop. I'm a beginner to understanding Linux/Unix systems. Could someone explain:
- How I can contain this within a multiline function in my <code>bash_profile</code> as opposed to an alias?
- What exactly is going on when I execute these commands? I understand an alias is only a stored value...how does that affect the behavior here?</p>

Rhubarb
<p>I'm not sure what code you have in the <code>...</code> it might be what causes the error.<br>
But her what i have done and it worked.</p>
<p>Here is what i changed:<br>
I  used <code>docker</code> instead of <code>docker-compose</code>.<br>
I added <code>-it</code> flags.<br>
Also added <code>CONTAINER=$1</code> to get the container name as parameter.<br></p>
<pre><code>function container {                        
        CONTAINER=$1                        
        echo &quot;Your code here&quot;                     
        docker exec -it $CONTAINER /bin/bash
}                                           
</code></pre>
<p>Just put it in <code>.bashrc</code> or <code>.bash_profile</code> and it works.<br>
As far as i understand <code>.bash_profile</code> and <code>.bashrc</code> are just shell script that get sourced into current session any time you open new shell.<br>
So Any function you put inside will be available as if you run it in regular script.</p>
<p>You can also source more files inside them to keep them clean and make your custom commands and functions more portable.<br>
Like this:<code>.bash_profile</code></p>
<pre><code># dotfile dir is actually a git repo that i clone to any new machine i use.
# And Add this line only to my .bash_profile
if [ -f ~/dotfiles/.bash_customize ]; then
    . ~/dotfiles/.bash_customize
fi
</code></pre>
