When I write bash script and I have
exit;;
or
exit 0;;
the script not only exits but the window (or pane in the case of tmux panes) exits completely (goes away).
e.g.
while true; do
read -p 'Run with -a (auto-correct) options?' yn
case $yn in
[Yy]* ) rubocop -a $@;;
[Nn]* ) exit;; # <--here exits window completely !
* ) echo "Yes or No!";;
esac
done
How can I prevent this?
My bashrc is:
HISTCONTROL=ignoreboth:erasedups HISTSIZE=100000 HISTFILESIZE=200000
shopt -s histappend checkwinsize
PROMPT_COMMAND='history -a'
test -f ~/.bash_functions.sh && . $_ # I can comment these out & it doesn't help
test -f ~/.bash_aliases && . $_
test -f ~/.eq_aliases && . $_
test -f ~/.git-completion.bash && . $_
test -f /etc/bash_completion && ! shopt -oq posix && . /etc/bash_completion
test -f ~/.autojump/etc/profile.d/autojump.sh && . $_
ls --color=al > /dev/null 2>&1 && alias ls='ls -F --color=al' || alias ls='ls -G'
HOST='\[\033[02;36m\]\h'; HOST=' '$HOST
TIME='\[\033[01;31m\]\t \[\033[01;32m\]'
LOCATION=' \[\033[01;34m\]`pwd | sed "s#\(/[^/]\{1,\}/[^/]\{1,\}/[^/]\{1,\}/\).*\(/[^/]\{1,\}/[^/]\{1,\}\)/\{0,1\}#\1_\2#g"`'
BRANCH=' \[\033[00;33m\]$(git_branch)\[\033[00m\]\n\$ '
PS1=$TIME$USER$HOST$LOCATION$BRANCH
PS2='\[\033[01;36m\]>'
set -o vi # vi at command line
export EDITOR=vim
export PATH="/usr/local/heroku/bin:$PATH" # Added by the Heroku Toolbelt
export PYTHONPATH=/usr/local/lib/python2.7/site-packages/ # for meld mdd 4/19/2014
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" # friendly for non-text files
[ ${BASH_VERSINFO[0]} -ge 4 ] && shopt -s autocd
#[ `uname -s` != Linux ] && exec tmux
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
export PATH=$HOME/.node/bin:$PATH
scriptnameorsource scriptnameor. scriptname? The latter two are equivalent and will run it in the shell itself, not as a subprocess, so yes,exitwill close the window ifSHLVLis 1..but also finding that usingreturn;;instead ofexitwill workreturnonly works in functions and sourced scripts, so if you're using.orsource, usereturn../scriptname(the easiest imHo) orbash scriptname.