Bash: Execute a Function as Sudo within a Script: Difference between revisions

From WikiMLT
mNo edit summary
 
(No difference)

Latest revision as of 12:06, 3 August 2022

Prob­a­bly the sim­plest way is the fol­low:

#!/bin/bash

# Define the function
main() { ... }

sudo -b bash -c "$(declare -f main); main"

Ref­er­ences: