How to implement an "Are you root?" test in a shell script

Forum rules
Before you post please read how to get help
Paul_Pedant
Level 1
Level 1
Posts: 33
Joined: Wed Sep 25, 2019 1:34 pm
Location: Bath, UK

Re: How to implement an "Are you root?" test in a shell script

Post by Paul_Pedant » Wed Sep 25, 2019 5:54 pm

Somewhere above, I found: "However, there are times when I am going to be doing a lot of work as "root" at the same time, and typing "sudo" a half-a-zillion times is a Royal Pain In The Tush."
In my user-level terminal bash session, I just type "sudo bash", give the password as requested, and then I can issue any number of commands at sudo level. The entire bash session has sudo privileges, and each command inherits them. There is no time-out.
I automatically get a distinctive prompt (red, with a #) at every command to remind me who I am (i.e. how much damage I might be risking).
I can exit or Ctrl-D to terminate the sudo bash, and return to my user level.
Last edited by karlchen on Wed Sep 25, 2019 5:58 pm, edited 1 time in total.
Reason: closed the 3 year old thread in order to prevent it from being revived once every year. ;-)

Locked

Return to “Scripts & Bash”