Skip to content

Instantly share code, notes, and snippets.

@lijiext
Last active May 8, 2024 16:26
Show Gist options
  • Save lijiext/c9c5ca4d3b16c335dcae091902c6f16b to your computer and use it in GitHub Desktop.
Save lijiext/c9c5ca4d3b16c335dcae091902c6f16b to your computer and use it in GitHub Desktop.
confirm function in shell
# Asks the user a yes/no question and waits for a response. Takes the question
# text as its only argument. The user must enter either "y" or "n" to proceed.
confirm()
{
while true; do
read -r -p "$1" RESPONSE
case "$RESPONSE" in
[yY]) return 0 ;;
[nN]) return 1 ;;
*) echo "Please enter y or n"
esac
done
}
confirm "Install the xorg-x11-drv-void package? [y/n]: " && \
yum install xorg-x11-drv-void
confirm "Are you sure? [y/n]: " || exit 0
# 判断文件是否存在
if [ ! -f "$XORG_MODULE_DIR/input/void_drv.so" ] &&
[ ! -f "$XORG_MODULE_DIR64/input/void_drv.so" ]; then
echo "WARNING: Xorg void input driver not found."
# 判断是否是root
if [ -z "$IS_ROOT" ]; then
echo "Re-run as root to install Xorg void input driver package."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment