S
S
seiwer-tail2021-05-06 14:41:29
bash
seiwer-tail, 2021-05-06 14:41:29

How to prevent the script from closing when executing commands?

Hi all! In general, I am writing my installer script for mobile devices and noticed such a strange thing that when executing sudo commands, the script just dies and closes

. How can I fix this?

(a piece of code where it happens

echo "What would you like to do?"
echo "i - Install Anbox "
echo "q - What problems can I face after installation "
echo "e - exit "
echo " "
echo " "
read -p "answer: " menu
case $menu in
i) echo " Preparatory work will be done now. The system will now ask for a password to install the screenfetch and android-tools package"
   echo " "
   read -p "Press enter to start preparation" prepare
   exec sudo mount -o remount, rw /
   exec sudo apt install -y screenfetch anbox-ubuntu-touch  android-tools-adb
   exec cd /home/phablet/ 
   exec mkdir /home/phablet/anbox-data
   echo "Excellent! Let us ask a couple of questions before starting the installation to start the installation"
   echo "Don't worry, the questions will be easy"


The death of the script occurs after this command: exec sudo mount -o remount, rw /
The system asks for a password, I enter it, the command is executed and the script does not continue to work, but it just throws me into the console itself (that is, the script closes) and I need to somehow force the script do not close and continue executing the script further

Thank you in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vaut, 2021-05-06
@seiwer-tail

You are not using exec correctly, it is not needed here at all.

$ man bash
exec [-cl] [-a name] [command [arguments]]
              If command is specified, it replaces the shell.  No new  process
              is  created.  The arguments become the arguments to command.  If
              the -l option is supplied, the shell places a dash at the begin‐
              ning  of  the  zeroth  argument passed to command.  This is what
              login(1) does.  The -c option causes command to be executed with
              an  empty environment.  If -a is supplied, the shell passes name
              as the zeroth argument to the executed command.  If command can‐
              not  be executed for some reason, a non-interactive shell exits,
              unless the execfail shell option is enabled.  In that  case,  it
              returns  failure.   An  interactive shell returns failure if the
              file cannot be executed.  If command is not specified, any redi‐
              rections take effect in the current shell, and the return status
              is 0.  If there is a redirection error, the return status is 1.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question