Use the command xargs as input from a file to popular Xdialog --radiolist

Asked

Viewed 41 times

1

The question here is very simple!

Here is a variable:

arquivo="\"Item 1\" 'A' off \"Item 2\" 'B' off \"Item 3\" 'C' off \"Item 4\" 'D' off \"Item 5\" 'E' off \"Item 6\" 'F' off"

Note that the length of the variable contains the options for each check button.

Quotation marks should be escaped like this:

\"Item 1\"

Below this an excerpt that needs from a list length check:

echo $arquivo | xargs Xdialog --stdout --separate-output --radiolist 'Seu Texto Aqui' 0 0 0

RESULT:

inserir a descrição da imagem aqui


Instead of writing the options in a variable to dynamically popular to Xdialog, need to use a file as input to populate.

EXAMPLE:

cat /tmp/arquivo.txt | xargs Xdialog --stdout --separate-output --radiolist 'Seu Texto Aqui' 0 0 0

FILING CABINET:

\"Item 1\"  'A'     off
\"Item 2\"  'B'     off
\"Item 3\"  'C'     off
\"Item 4\"  'D'     off
\"Item 5\"  'E'     off
\"Item 6\"  'F'     off

PRINT SCREEN:

inserir a descrição da imagem aqui

In the manual of xargs, I found this information that I think is the solution to the question:

$ man xargs
...
       --arg-file=arquivo
       -a arquivo

              Leia itens do arquivo em vez da entrada padrão. Se você usar isso
              opção, stdin permanece inalterado quando os comandos são executados. De outros-
              sábio, stdin é redirecionado de /dev/null.
...

I tried to implement it. but it didn’t work.

References

1- https://www.linuxquestions.org/questions/slackware-14/dialog-radiolist-with-list-from-file-to-choose-not-working-930774/
2- Checklist and Dialog with external file - Shell Script
3- https://aurelio.net/shell/dialog

1 answer

0


Let’s solve:

FILING CABINET:

The big problem here is that since the name has blank spaces, each word is seen as a parameter and messes up the menu. The solution is to put the name between "escaped quotes " and use the eval to execute the command.

\"Item 1\"  'A'     off
\"Item 2\"  'B'     off
\"Item 3\"  'C'     off
\"Item 4\"  'D'     off
\"Item 5\"  'E'     off
\"Item 6\"  'F'     off

STEP-BY-STEP

$ arquivo=`cat /tmp/arquivo.txt`

$ eval echo $arquivo | xargs Xdialog --stdout --separate-output --radiolist 'Seu Texto Aqui' 0 0 0

RESULT PRINT

inserir a descrição da imagem aqui


IMPORTANT! - "In this context, you need to create a variable with the command cat to use with eval, followed by echo for him to see the content of variable $arquivo which will pass as parameter to the shell. Which in turn executes the commands xargs who reads the stdin to the Xdialog or dialog."


Basically that’s what each of these commands does:

  • The main use of cat is read content from files.

  • The eval combines arguments into a single string and the uses as an input for the shell and execute the commands.

  • The command echo besides showing messages on the screen, serves to see the value of variables of the system or that you create.

  • The command xargs is used to build and execute command lines on Linux. It is common to need to pass a list of items to a command that is larger than the shell can work. The command xargs can be used to make a division of that list into smaller sub-lists, and pass the arguments to the requested command (in our case it is the - Xdialog or dialog), in parts.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.