Я написал небольшую библиотечную функцию, чтобы помочь мне выйти, когда владелец скрипта не является root:
#!/bin/bash
# Exit for non-root user
exit_if_not_root() {
if [ "$(id -u)" == "0" ]; then return; fi
if [ -n "$1" ];
then
printf "%s" "$1"
else
printf "Only root should execute This script. Exiting now.\n"
fi
exit 1
}
Здесь я вызываю его из другого файла:
#!/bin/bash
source ../bashgimp.sh
exit_if_not_root "I strike quickly, being moved. But thou art not quickly moved to strike.\n You're not root, exiting with custom message."
И вывод:
I strike quickly, being moved. But thou art not quickly moved to strike.\n You're not root, exiting with custom message.
Как сделать так, чтобы символ новой строки отображался правильно?