Bash: Execute a Function as Sudo within a Script: Difference between revisions
From WikiMLT
m (Стадий: 6 [Фаза:Утвърждаване, Статус:Утвърден]; Категория:Linux Server) |
mNo edit summary |
||
Line 14: | Line 14: | ||
* [https://unix.stackexchange.com/a/269080/201297 Executing a Bash Script Function with Sudo] | * [https://unix.stackexchange.com/a/269080/201297 Executing a Bash Script Function with Sudo] | ||
* [https://stackoverflow.com/q/9448920/6543935 How can I execute a bash function using sudo?] | * [https://stackoverflow.com/q/9448920/6543935 How can I execute a bash function using sudo?] | ||
<noinclude> | <noinclude> | ||
<div id='devStage'> | <div id='devStage'> |
Revision as of 12:03, 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?