Need to Change $Euid Value to Non-Zero in the Bash Shell

I have a script(test1.sh) like the below and i need to run it as root because As a prerequisites, we need to install a couple of packages when it enters into this script, value $EUID should be non-zero, Coul you help me to change this $EUID value

test1.sh


#!/usr/bin/env bash


....
.....

    if [[ $EUID -eq 0 ]]; then
       echo "This script must be run as nonroot user. Otherwise, couple of test cases will fail."
       exit 1
    fi

.........
..........
.............
.....

..
.
.
.
.............

Thank you

1 Answer

Read man sudo and use -u user, e.g.

sudo -u nobody /path/to/the/script
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest