Skip to main content
Alternative subshell with bash -c '...'
Source Link
sudodus
  • 6.7k
  • 17
  • 27

Graphical desktop environment

You can run the command in another terminal window (if you have a graphical desktop environment).

The following shellscript uses xterm, which can be installed with

sudo apt update
sudo apt install xterm

but you can use other terminal window emulators too, for example gnome-terminal or lxterminal.

Shellscript:

#!/bin/bash

select opt in "dbus-monitor --system" htop exit; do
    case $REPLY in
      1)
        xterm -e dbus-monitor --system 2>/dev/null
        ;;
      2)
        htop
        ;;
      3)
        exit
        ;;
    esac
done

Text screen (this method works also in a graphical desktop)

You can use the trap method in @RoVo's answer.

The important thing is to run the trap command before you run the command, that you must interrupt with ctrl+c. So if you want it in the whole menu script, put it in the beginning. If you want it only when it is absolutely necessary, run a subshell and put the trap command inside the subshell as illustrated by @RoVo.

  • So if you want it in the whole menu script, put it in the beginning.

  • If you want it only when it is absolutely necessary, run a subshell and put the trap command inside the subshell as illustrated by @RoVo, alternatively with

      bash -c 'trap "kill -SIGINT 0" SIGINT; dbus-monitor --system';;
    

Shellscript:

#!/bin/bash

echo "Press the Enter key to print out the menu again"

trap "kill -SIGINT 0" SIGINT

select opt in "dbus-monitor --system" "option 2" "Quit"
do
    case $opt in
        "dbus-monitor --system")
            dbus-monitor --system;;   
        "option 2")
            echo "Hello World";;   
        "Quit")
            exit;;
    esac
done

Comment

Your curl command line did not work for me, so I invoke my local dbus-monitor to test that the shellscript works when using ctrl+c.

Graphical desktop environment

You can run the command in another terminal window (if you have a graphical desktop environment).

The following shellscript uses xterm, which can be installed with

sudo apt update
sudo apt install xterm

but you can use other terminal window emulators too, for example gnome-terminal or lxterminal.

Shellscript:

#!/bin/bash

select opt in "dbus-monitor --system" htop exit; do
    case $REPLY in
      1)
        xterm -e dbus-monitor --system 2>/dev/null
        ;;
      2)
        htop
        ;;
      3)
        exit
        ;;
    esac
done

Text screen (this method works also in a graphical desktop)

You can use the trap method in @RoVo's answer.

The important thing is to run the trap command before you run the command, that you must interrupt with ctrl+c. So if you want it in the whole menu script, put it in the beginning. If you want it only when it is absolutely necessary, run a subshell and put the trap command inside the subshell as illustrated by @RoVo.

#!/bin/bash

echo "Press the Enter key to print out the menu again"

trap "kill -SIGINT 0" SIGINT

select opt in "dbus-monitor --system" "option 2" "Quit"
do
    case $opt in
        "dbus-monitor --system")
            dbus-monitor --system;;   
        "option 2")
            echo "Hello World";;   
        "Quit")
            exit;;
    esac
done

Comment

Your curl command line did not work for me, so I invoke my local dbus-monitor to test that the shellscript works when using ctrl+c.

Graphical desktop environment

You can run the command in another terminal window (if you have a graphical desktop environment).

The following shellscript uses xterm, which can be installed with

sudo apt update
sudo apt install xterm

but you can use other terminal window emulators too, for example gnome-terminal or lxterminal.

Shellscript:

#!/bin/bash

select opt in "dbus-monitor --system" htop exit; do
    case $REPLY in
      1)
        xterm -e dbus-monitor --system 2>/dev/null
        ;;
      2)
        htop
        ;;
      3)
        exit
        ;;
    esac
done

Text screen (this method works also in a graphical desktop)

You can use the trap method in @RoVo's answer.

The important thing is to run the trap command before you run the command, that you must interrupt with ctrl+c.

  • So if you want it in the whole menu script, put it in the beginning.

  • If you want it only when it is absolutely necessary, run a subshell and put the trap command inside the subshell as illustrated by @RoVo, alternatively with

      bash -c 'trap "kill -SIGINT 0" SIGINT; dbus-monitor --system';;
    

Shellscript:

#!/bin/bash

echo "Press the Enter key to print out the menu again"

trap "kill -SIGINT 0" SIGINT

select opt in "dbus-monitor --system" "option 2" "Quit"
do
    case $opt in
        "dbus-monitor --system")
            dbus-monitor --system;;   
        "option 2")
            echo "Hello World";;   
        "Quit")
            exit;;
    esac
done

Comment

Your curl command line did not work for me, so I invoke my local dbus-monitor to test that the shellscript works when using ctrl+c.

added 24 characters in body
Source Link
sudodus
  • 6.7k
  • 17
  • 27

Graphical desktop environment

You can run the command in another terminal window (if you have a graphical desktop environment).

The following shellscript uses xterm, which can be installed with

sudo apt update
sudo apt install xterm

but you can use other terminal window emulators too, for example gnome-terminal or lxterminal.

Shellscript:

#!/bin/bash

select opt in "dbus-monitor --system" htop exit; do
    case $REPLY in
      1)
        xterm -e dbus-monitor --system 2>/dev/null
        ;;
      2)
        htop
        ;;
      3)
        exit
        ;;
    esac
done

Text screen (this method works also in a graphical desktop)

UseYou can use the trap method in @RoVo's answer.

The important thing is to run the trap command before you run the command, that you must interrupt with ctrl+c. So if you want it in the whole menu script, put it in the beginning. If you want it only when it is absolutely necessary, run a subshell and put the trap command inside the subshell as illustrated by @RoVo.

#!/bin/bash

echo "Press the Enter key to print out the menu again"

trap "kill -SIGINT 0" SIGINT

select opt in "dbus-monitor --system" "option 2" "Quit"
do
    case $opt in
        "dbus-monitor --system")
            dbus-monitor --system;;   
        "option 2")
            echo "Hello World";;   
        "Quit")
            exit;;
    esac
done

Comment

Your curl command line did not work for me, so I invoke my local dbus-monitor to test that the shellscript works when using ctrl+c.

Graphical desktop environment

You can run the command in another terminal window (if you have a graphical desktop environment).

The following shellscript uses xterm, which can be installed with

sudo apt update
sudo apt install xterm

but you can use other terminal window emulators too, for example gnome-terminal or lxterminal.

Shellscript:

#!/bin/bash

select opt in "dbus-monitor --system" htop exit; do
    case $REPLY in
      1)
        xterm -e dbus-monitor --system 2>/dev/null
        ;;
      2)
        htop
        ;;
      3)
        exit
        ;;
    esac
done

Text screen

Use can use the trap method in @RoVo's answer.

The important thing is to run the trap command before you run the command, that you must interrupt with ctrl+c. So if you want it in the whole menu script, put it in the beginning. If you want it only when it is absolutely necessary, run a subshell and put the trap command inside the subshell as illustrated by @RoVo.

#!/bin/bash

echo "Press the Enter key to print out the menu again"

trap "kill -SIGINT 0" SIGINT

select opt in "dbus-monitor --system" "option 2" "Quit"
do
    case $opt in
        "dbus-monitor --system")
            dbus-monitor --system;;   
        "option 2")
            echo "Hello World";;   
        "Quit")
            exit;;
    esac
done

Comment

Your curl command line did not work for me, so I invoke my local dbus-monitor to test that the shellscript works when using ctrl+c.

Graphical desktop environment

You can run the command in another terminal window (if you have a graphical desktop environment).

The following shellscript uses xterm, which can be installed with

sudo apt update
sudo apt install xterm

but you can use other terminal window emulators too, for example gnome-terminal or lxterminal.

Shellscript:

#!/bin/bash

select opt in "dbus-monitor --system" htop exit; do
    case $REPLY in
      1)
        xterm -e dbus-monitor --system 2>/dev/null
        ;;
      2)
        htop
        ;;
      3)
        exit
        ;;
    esac
done

Text screen (this method works also in a graphical desktop)

You can use the trap method in @RoVo's answer.

The important thing is to run the trap command before you run the command, that you must interrupt with ctrl+c. So if you want it in the whole menu script, put it in the beginning. If you want it only when it is absolutely necessary, run a subshell and put the trap command inside the subshell as illustrated by @RoVo.

#!/bin/bash

echo "Press the Enter key to print out the menu again"

trap "kill -SIGINT 0" SIGINT

select opt in "dbus-monitor --system" "option 2" "Quit"
do
    case $opt in
        "dbus-monitor --system")
            dbus-monitor --system;;   
        "option 2")
            echo "Hello World";;   
        "Quit")
            exit;;
    esac
done

Comment

Your curl command line did not work for me, so I invoke my local dbus-monitor to test that the shellscript works when using ctrl+c.

Added detailed description how to use trap
Source Link
sudodus
  • 6.7k
  • 17
  • 27

Graphical desktop environment

You can run the command in another terminal window (if you have a graphical desktop environment).

The following shellscript uses xterm, which can be installed with

sudo apt update
sudo apt install xterm

but you can use other terminal window emulators too, for example gnome-terminal or lxterminal.

Shellscript:

#!/bin/bash

select opt in "dbus-monitor --system" htop exit; do
    case $REPLY in
      1)
        xterm -e dbus-monitor --system 2>/dev/null
        ;;
      2)
        htop
        ;;
      3)
        exit
        ;;
    esac
done

Text screen

Use can use the trap method in @RoVo's answer.

The important thing is to run the trap command before you run the command, that you must interrupt with ctrl+c. So if you want it in the whole menu script, put it in the beginning. If you want it only when it is absolutely necessary, run a subshell and put the trap command inside the subshell as illustrated by @RoVo.

#!/bin/bash

echo "Press the Enter key to print out the menu again"

trap "kill -SIGINT 0" SIGINT

select opt in "dbus-monitor --system" "option 2" "Quit"
do
    case $opt in
        "dbus-monitor --system")
            dbus-monitor --system;;   
        "option 2")
            echo "Hello World";;   
        "Quit")
            exit;;
    esac
done

Comment

Your curl command line did not work for me, so I invoke my local dbus-monitor to test that the shellscript works when using ctrl+c.

You can run the command in another terminal window (if you have a graphical desktop environment).

The following shellscript uses xterm, which can be installed with

sudo apt update
sudo apt install xterm

but you can use other terminal window emulators too, for example gnome-terminal or lxterminal.

Shellscript:

#!/bin/bash

select opt in "dbus-monitor --system" htop exit; do
    case $REPLY in
      1)
        xterm -e dbus-monitor --system 2>/dev/null
        ;;
      2)
        htop
        ;;
      3)
        exit
        ;;
    esac
done

Graphical desktop environment

You can run the command in another terminal window (if you have a graphical desktop environment).

The following shellscript uses xterm, which can be installed with

sudo apt update
sudo apt install xterm

but you can use other terminal window emulators too, for example gnome-terminal or lxterminal.

Shellscript:

#!/bin/bash

select opt in "dbus-monitor --system" htop exit; do
    case $REPLY in
      1)
        xterm -e dbus-monitor --system 2>/dev/null
        ;;
      2)
        htop
        ;;
      3)
        exit
        ;;
    esac
done

Text screen

Use can use the trap method in @RoVo's answer.

The important thing is to run the trap command before you run the command, that you must interrupt with ctrl+c. So if you want it in the whole menu script, put it in the beginning. If you want it only when it is absolutely necessary, run a subshell and put the trap command inside the subshell as illustrated by @RoVo.

#!/bin/bash

echo "Press the Enter key to print out the menu again"

trap "kill -SIGINT 0" SIGINT

select opt in "dbus-monitor --system" "option 2" "Quit"
do
    case $opt in
        "dbus-monitor --system")
            dbus-monitor --system;;   
        "option 2")
            echo "Hello World";;   
        "Quit")
            exit;;
    esac
done

Comment

Your curl command line did not work for me, so I invoke my local dbus-monitor to test that the shellscript works when using ctrl+c.

Source Link
sudodus
  • 6.7k
  • 17
  • 27
Loading