Bash: Execute a Function as Sudo within a Script: Difference between revisions
From WikiMLT
mNo edit summary |
m (Spas moved page Bash Execute a Function as Sudo within a Script to Bash: Execute a Function as Sudo within a Script without leaving a redirect) |
(No difference)
|
Latest revision as of 12:06, 3 August 2022
Probably the simplest way is the follow:
#!/bin/bash
# Define the function
main() { ... }
sudo -b bash -c "$(declare -f main); main"
References:
- Auto login – LughtDM – SSH
- Display terminal command result in Desktop notification
- Executing a Bash Script Function with Sudo
- How can I execute a bash function using sudo?