0

I am trying to build a terminal based GUI for a tool. The following code invokes something like this

while true
do
   CHOICE=$(dialog --keep-window --clear --no-shadow \
                --backtitle "$BACKTITLE" \
                --title "$TITLE" \
                --menu "$MENU" \
                $HEIGHT $WIDTH $CHOICE_HEIGHT \
                "${OPTIONS[@]}" \
                2>&1 >/dev/tty)

   clear

   case $CHOICE in
   #*) exec vim "$(echo $CHOICE  | cut -d ':' -f 1)" ;  ;;
   *)  filename="$(echo $CHOICE | cut -d ':' -f 1)"
       #mkfifo "$TOMATO_DIR/cf"
       if [ ! -z $filename ] ; then
           dialog --editbox $filename 60 80
           #cp "$TOMATO_DIR/cf" $filename
           #rm -f ${INPUT}
       else
           clear
           exit 0
       fi
       clear ;;
   esac

done

enter image description here

And on pressing ENTER and editbox as following opens: enter image description here

I tried opening the file in vim but on saving the file, the tools exits.
I want to know, how to open the file and return to the tool on saving or exiting from vim ?

  • 1
    did you use exec vim ... or vim ... in former case, shell will be replaced by vim, and upon vim exit will dissapear. try using later case. – Archemar Sep 28 '16 at 11:21
  • @Archemar That worked perfectly !! Can you please explain why this happens ? – lordzuko Sep 28 '16 at 11:41
0

exec is a shell builtin as per bash man page (be patient, it is far away)

   exec [-cl] [-a name] [command [arguments]]
          If command is specified, it replaces the shell.  No new process is created.

consider 2 script

exec ls
pwd

and

ls
pwd

if you execute the first shell, exec ls command will replace shell (discarding remaining input), pwd command will never get exectued.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.