0
我正嘗試創建一個shell腳本,它使用root訪問權限來安裝所有依賴項,並且在完成它之後,它將從root命令退出並繼續執行該腳本與普通用戶一樣。在shell腳本中執行root命令,並在進程後更改爲普通用戶
這是測試代碼:
#!/bin/sh
output=$(whoami)
if [ "$(whoami)" != "root" ]
then
su -c "echo \"hi\""
echo $output
//continue doing some installtion
exit
fi
echo $output //this should show the normal username not the root name
我試過這種方法有沒有其他方法? – anonymous5671