Without further arguments su will run the login shell for root. That's what the first line of your script actually does. When you exit, the login shell closes, su returns and your script continues execution, that is with the second line: ls /root. I think you can simply sudo ls /root to do what you want.

Stack Exchange Network. Stack Exchange network consists of 177 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.. Visit Stack Exchange How To Use 'Sudo' And 'Su' Commands In Linux : An Jan 11, 2015 37 Important Linux Commands You Should Know May 08, 2019 Linux exit command - javatpoint Linux exit command. Linux exit command is used to exit from the current shell. It takes a parameter as a number and exits the shell with a return of status number. If we did not provide any parameter, it would return the status of the last executed command. The exit command closes a script and exits the shell.

NAME. exit-The exit command terminates a script, just as in a C program.It can also return a value, which is available to the script's parent process. SYNOPSIS exit DESCRIPTION. exit-Issuing the exit command at the shell prompt will cause the shell to exit.In some cases, if you have jobs running in the background, the shell will remind you that they are running and simply return you to the

How to Switch User Using the "su" Command Nov 10, 2019 exit command in Linux with Examples - GeeksforGeeks exit command in linux is used to exit the shell where it is currently running. It takes one more parameter as 713 and exits the shell with a return of status N. If n is not provided, then it simply returns the status of last command that is executed. exit n : Using “sudo su” we are going to the root directory and then exit …

How to quit vi, vim, emacs, nano, joe, jed, ed, ex and other command line / terminal editors. Someone once said that if you want a random string, put a newbie in front of a Unix editor and ask them to quit.

You don't need to use sudo and su together--su switches your user account (without arguments it switches you to root). sudo just elevates your privileges to root for the current command. It's reccomended to use sudo instead of su if possible, but to return to your normal account after calling su, simply use the exit command The su Command - The Linux Information Project (LINFO Exiting From su. There are several ways to exit from su, i.e., to return the login session or terminal window to its former owner, for those situations in which the exit is not automatic (e.g., when su is not used with its -c option). One is to type the word exit and then press the ENTER key. Another is to simultaneously press the CTRL and d keys. How to Switch User Using the "su" Command Nov 10, 2019 exit command in Linux with Examples - GeeksforGeeks