I have such code:
echo 'test'
usr=$USER
sudo sh -c "exec su $usr"
echo 'test1'
And for example echo 'test'
is code where I configuring something that requirs me to relogin in new shell. But then where code is echo 'test1'
I need to continue configuring using reloaded new shell.
Is there way to do that automatically? Like start new shell in parallel or something like that?
Ubuntu 14.04, bash.
Update:
For example, I need to install virsh but after installation it requires sudo to run. My script configurs groups adding $USER to the libvirtd group. Then I need to relogin. I can do that with sudo sh -c "exec su $usr"
. After that I need the script to continue execution. Is there way to do that?
Change with visudo
your sudoers configuration so that you are no longer asked for a password. See man visudo
and man sudoers
.
I suggest to use a heredoc :
echo 'test'
usr="$USER"
sudo su - "$USER" << EOF
echo 'test1'
EOF
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.