title: Bash script not exiting with "exit" without subshells (I think)
body: <p>I'm using <code>stow</code> to manage my dotfiles and I'm writing a script that can set up my pc and packages automatically. I have all my config files in a <code>config</code> folder and that's the stow folder. What I'm basically doing is get the names of all folders (packages) in that folder and stowing them to my home directory. I also have a function that simply tells me if there was an error and exits the script.</p>
  <p>I'm running this script on Arch Linux, recently installed, on the tty (I haven't installed a window manager yet). And when it goes to stow bash, it fails because <code>.bashrc</code> already exists in home. It gives me the error message, but it doesn't exit and I can't find the reason. I don't think I'm running the <code>error</code> function on a subshell like I've seen from other people with this problem, unless there's something I'm missing here...</p>
  <p>Here's the function:</p>
  <pre><code>error () {
      echo &quot;!! ${1} !!&quot;
      exit 1
  }
  </code></pre>
  <p>And then later on I have something like this:</p>
  <pre><code>ls -1 config | while read line; do
      stow -d config -t ~ -R &quot;${line}&quot; || error &quot;Failed to stow ${line}.&quot;
  done
  </code></pre>
  <p>Here's the whole code from the creation of the function to the stowing:</p>
  <pre><code>step () {
      echo &quot;&gt; ${1}&quot;
  }
  
  substep () {
      echo &quot;--&gt; ${1}&quot;
  }
  
  error () {
      echo &quot;!! ${1} !!&quot;
      exit 1
  }
  
  success () {
      echo &quot;** ${1} **&quot;
  }
  
  commandexists () {
      # Check if a command exists
      command -v $1 &amp;&gt; /dev/null
      if [[ $? -eq 0 ]]; then
          return 0
      else
          return 1
      fi
  }
  
  pkg-install () {
      pkg=&quot;${1:?&quot;Error: pkg parameter unset.&quot;}&quot;
  
      step &quot;${msg_install}: ${pkg}&quot;
  
      substep &quot;Installing ${pkg} from the Arch Linux Repositories.&quot;
      sudo pacman -Sy --noconfirm --needed &quot;$pkg&quot;
  
      if [[ $? -ne 0 ]]; then
          substep &quot;Installing ${pkg} from the Arch User Repositories.&quot;
          yay -Sy --noconfirm --needed &quot;$pkg&quot; || error &quot;${msg_fail_install}: ${pkg}&quot;
      fi
  
      success &quot;${msg_success_install}: ${pkg}&quot;
  }
  
  # Stop installation if yay is not installed
  commandexists yay || error &quot;Yay is not installed! Please install yay and try again.&quot;
  
  # stow
  pkg-install stow
  
  step &quot;Stowing config files&quot;
  ls -1 config | while read line; do
      substep &quot;Stowing ${line}&quot;
      stow -d config -t ~ -R &quot;${line}&quot; || error &quot;Failed to stow ${line}.&quot;
  done
  success &quot;Successfully stowed all config files&quot;
  </code></pre>
  <p>As you can see, before stowing it checks if <code>yay</code> is installed by checking if the command exists. If not, it gives me an error and exits. When I run this on my other pc that doesn't have <code>yay</code> installed, it works as expected. It tells me yay is not installed and stops there. But why does it ignore the <code>exit</code> command in the stow part when I run it on the pc that has <code>yay</code> installed?</p>