#!/usr/bin/env bash
((!EUID)) && { # check if the EUID is a zero
echo "${0##*/} can not be executed as root " # notify
exit 1 # exist with status code 1
}
gem install jekyll
since you are an admin (normal user) the variable $EUID always greater than zero !
and in root $EUID = 0
((expression))
The expression is evaluated according to the rules described below under ARITHMETIC EVALUATION. If the value of the expression is non-zero, the return status is
0; otherwise the return status is 1. This is exactly equivalent to let "expression"
or
#!/usr/bin/env bash
[[ $EUID = 0 ]] && { # check if the EUID is eq to zero
echo "${0##*/} can not be executed as root " # notify
exit 1 # exist with status code 1
}
gem install jekyll
i prefer this one
((EUID)) || exit 1
or
((!EUID)) && exit 1

updates after question edit
#!/usr/bin/env bash
((!EUID)) && {
#stuff to be exec as root
for option in update 'upgrade -y'
do
apt-get $option
done
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable --ruby
source /usr/local/rvm/scripts/rvm
} || {
#stuff to be exec as non-root
gem install jekyll
}
exit 0
now it will run in both root and non-root users but it will exec only a part of the script according to the EUID
sudo
then don't add sudo in front of that command. Please edit your question and clarify what you are trying to do and how it is failing.NOPASSWD:
option for use with this specific script.