I have got a small snippet (which is part of a script). It makes an array of windows to be displayed by tmux then echo the whole array. This snippet works fine when running in a simple file.sh.
mtmux() {
#tmux kill-server &>/dev/null
#[[ $(ps -ef | grep 'tmux attach-sess' | grep -v grep) ]] && kill -9 $(ps -ef | grep 'attach-sess' | grep -v grep | awk '{ print $2 }') &>/dev/null
#[[ $(pgrep tmux) ]] && pkill tmux &>/dev/null
pkill tmux >/dev/null
#I input the name of each window that tmux should display; when pressing 't', the loop stops
WINDOWS=()
IFS=$'\n'
while [ "${TITLE}" != 't' ]
do
read -p 'Add a new window?' TITLE
WINDOWS+=("${TITLE}")
done
#I remove the last element from the created array (cos it's just the 't' I passed to escape the loop).
unset WINDOWS[-1]
echo "${WINDOWS[@]}"
}
mtmux
As soon as I put it in my .bashrc, the unset command spawns the following error:
bash: unset: [-1]: bad array subscript
Issuing 'source ~/.bashrc' gives no error. Why such an error?
thanx folks!!