Bash - what's the use of "fi ;;"?
BashIf StatementBash Problem Overview
I have been searching everywhere for an explanation. Here's a real example taken from the apt-fast.sh script:
if [ ! -x /usr/bin/axel ]
then echo "axel is not installed, perform this?(y/n)"
read ops
case $ops in
y) if apt-get install axel -y --force-yes
then echo "axel installed"
else echo "unable to install the axel. you are using sudo?" ; exit
fi ;;
n) echo "not possible usage apt-fast" ; exit ;;
esac
fi
What's the use of "fi ;;"
in the middle of the if
block?
Bash Solutions
Solution 1 - Bash
fi
closes the if
statement, while ;;
closes the current entry in the case
statement.
Solution 2 - Bash
The fi
is to close the if-block in the y)
case statement and the ;;
is used to end the y)
case.
Solution 3 - Bash
fi
terminates the preceding if
, while ;;
terminates the y)
case in the case...esac
.
Solution 4 - Bash
fi
closes the if
statement opened 3 lines up. ;;
closes the case opened by y)
.