BASH Function to Check if sudo Available

in #programming3 years ago

sudo is the command to allow normal users perform some escalated operations. We can use the following BASH function to check to see if the sudo command is available. This is done via the which command which searches the command in the $PATH path.

# 0 - ok
# 1 - nok
is_sudo_available()
{
    local result=1
    which sudo 2>&1 1>/dev/null
    [ $? -eq 0 ] && result=0
    return $result
}

This function works in BASH script on Linux platforms and also the Windows Subsystem for Linux or Cygwin.

--EOF (The Ultimate Computing & Technology Blog) --

Reposted to Blog

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Thank you for reading ^^^^^^^^^^^^^^^

NEW! Following my Trail (Upvote or/and Downvote)

Follow me for topics of Algorithms, Blockchain and Cloud.
I am @justyy - a Steem Witness
https://steemyy.com

My contributions

Delegation Service

Important Update of Delegation Service!

  • Delegate 1000 to justyy: Link
  • Delegate 5000 to justyy: Link
  • Delegate 10000 to justyy: Link

Support me

If you like my work, please:

  1. Delegate SP: https://steemyy.com/sp-delegate-form/?delegatee=justyy
  2. Vote @justyy as Witness: https://steemyy.com/witness-voting/?witness=justyy&action=approve
  3. Set @justyy as Proxy: https://steemyy.com/witness-voting/?witness=justyy&action=proxy
    Alternatively, you can vote witness or set proxy here: https://steemit.com/~witnesses

Coin Marketplace

STEEM 0.27
TRX 0.13
JST 0.032
BTC 62795.05
ETH 2941.10
USDT 1.00
SBD 3.55