Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7836389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:07:23+00:00 2026-06-02T14:07:23+00:00

I’m writing a script using multiple dialog screens in bash. One of the functions

  • 0

I’m writing a script using multiple dialog screens in bash. One of the functions of the script should be killing specific processes. I load all my PID values in one array called pid:

pid = ('1234' '1233' '1232' '1231' '1230')

Then I present the user with a dialog checklist that contains a list of the processes.
After they select some of them dialog returns the checklist entry number, for example 0,2,4.

My initial plan was to store the selected entries in a second array and then use it to get specific PID’s from the first array, but so far, nothing I’ve tried worked, in this case that would be: 1234, 1232, 1230. So I can kill those specific processes.

Does anyone have a better solution? I want the easiest way of killing processes based on selections made by the user at the dialog checklist.

Here is the function in question:

stop_tunnel() {

local tunnels
local pid
declare -a tunnels
declare -a pid

#this is executed on a remote system in the real script
ps aux | grep -w ssh > $_temp

awk -F "ssh" '{print "ssh" $2}' $_temp > $_temp1
awk '{print $2}' $_temp > $_temp2

IFS='
'
tunnels=( $( < $_temp1 ) )
pid=( $( < $_temp2 ) )

dialog --checklist "Select tunnel to stop:" 10 72 0 \
                   0 "${tunnels[0]}" off \
                   1 "${tunnels[1]}" off \
                   2 "${tunnels[2]}" off \
                   3 "${tunnels[3]}" off \
                   4 "${tunnels[4]}" off \
                   2>$_temp

nr=$( < $_temp )

dialog --title " Tunnel stop " --msgbox "\nYou stopped these tunnels: ${nr[@]}" 6 44

}

The nr array holds the users selection. And I wanted to use that to pull specific members out of the pid array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:07:24+00:00Added an answer on June 2, 2026 at 2:07 pm

    Select might be what you need:

    select p in ${pid[@]} ; do   echo "kill" $p && break; done
    

    Note that blanks around the assignment won’t work:

    # wrong:
    pid = ('1234' '1233' '1232' '1231' '1230')
    # right:
    pid=('1234' '1233' '1232' '1231' '1230')
    

    To allow to kill multiple processes in sequence:

    select p in ${pid[@]} ; do
      if [[ -n $p ]]
         then echo "kill" $p
         else break
      fi
    done
    1) 1234
    2) 1233
    3) 1232
    4) 1231
    5) 1230
    #? 3
    kill 1232
    #? 4
    kill 1231
    #? 6
    

    The echo is of course just for testing.

    A hint for the user, that an invalid index will terminate the process killing seems appropriate. A second approach could be an explicit termination case:

    pid=('1234' '1233' '1232' '1231' '1230' 'terminate')
    

    which you would handle with the break.

    If you just want to iterate over the selections, being made:

    sel=(0 2 4) 
    for n in ${sel[@]} ; do echo kill ${pid[$n]}; done  
    

    update towards you comment:

    I don’t have dialog installed, but I guess zenity is similar. There you capture the output of a list seleciton:

    selection=($(zenity --list --text "kill something" --multiple --column "kill" --separator " " --checklist --column ps TRUE foo FALSE bar FALSE baz TRUE fozboa))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am writing an app with both english and french support. The app requests

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.