Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a menu to append or overwrite ssh keys for multiple users using dialog --checklist. The menu is something like this

    0) append
    1) user1
    2) root

What I would like to happen is if option zero is selected and either option 1 or 2 or both are selected it would append rather than over writing the ssh keys when it regenerates.

I'm new to dialog and can't seem to come up with the logic needed to cause this to happen.

My first thought was to use the --separate-output option and somehow use grep on the results but there has to be a more elegant solution. Any help or advise is appreciated.

share|improve this question
up vote 1 down vote accepted

Run dialog like this:

dialog --checklist text 50 20 10 0 append 0 1 user1 0 2 root 0 2> checklist.txt

The 2> pipes stderr to its own file - which is where --checklist's output ends up.

Then read the conents of checklist.txt like this:

for a in $(cat checklist.txt); do
    if [ "$a" = "\"0\"" ]; then

    if [ "$APPEND" -eq 0 ]; then
        # Copy ssh key, without appending
        # Append ssh key
share|improve this answer
Thanks so much seeing it after you wrote it, it seems so logical! I wouldn't have thought of using a place holder variable like that. I wish I had the rep to upvote your answer! – ss0 Oct 31 '11 at 19:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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