title: Loop over bash aliases and run commands in script
body: <p>I'm trying to create a bash script which has a list of aliases and run them in my script. (This is just a simplified example, but it explains the situation). </p>
  
  <p>What should happen is I loop over my aliases and the script executes them one by one. </p>
  
  <p>alias_list.sh</p>
  
  <pre><code>#!/bin/bash
  
  alias al1="ls"
  alias al2="ls ."
  alias al3="ls .."
  </code></pre>
  
  <p>test_alias_loop.sh</p>
  
  <pre><code>#!/bin/bash -i
  
  # Expand aliases
  shopt -s expand_aliases
  source ~/Documents/test_ssh_bash/scripts/alias_list.sh
  
  # Exists just to get a list of aliases, proper version gets aliases from bash command
  aliases=$(printf "al1\nal2\nal3\n\n")
  
  for ssh_alias in $aliases; do
    echo "$ssh_alias"
    $ssh_alias
  done
  </code></pre>
  
  <p>This is what I get for the first command
  ./test_alias_loop.sh: line 12: al1: command not found</p>
  
  <p>But, when I just do </p>
  
  <pre><code>al1
  </code></pre>
  
  <p>The command runs and I get an ls of my current directory. </p>
  
  <p>How can I loop over a list of alias commands and actually run them in my script? </p>