ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a array called "usb_device" which has 3 elements as follows:
Code:
/dev/sda
/dev/sdb
/dev/sdc
Now I am trying to display these elements with the 'dialog' utility like this:
Code:
dialog --clear --title "List USB Devices" \
--menu "Move using [UP] [DOWN} Arrow keys, Hit [ENTER] key to select." 15 50 5 \
for (( i = 0; i < ${#get_usb_devices[@]}; i++ ))
do
$i $get_usb_devices \
done
exit 0
However when I try to run this I get following error:
Code:
./detect_usb.sh: line 10: syntax error near unexpected token `('
./detect_usb.sh: line 10: `for (( i = 0; i < ${#get_usb_devices[@]}; i++ ))'
I do not think this kind of construct is easily possible within Bash - in Common Lisp though, it would be quite simple, but that's besides the point.
I think you are going to have to work some magic with grep and awk (maybe sed, too) and wrap it in $() - see example. I would provide an example, but I have never used awk and/or sed before.
Example:
Code:
dialog --clear --title "List USB Devices" \
--menu "Move using [UP] [DOWN} Arrow keys, Hit [ENTER] key to select." 15 50 5 \
$(grep_awk_and_sed_magic)
I'm not entirely sure what you are trying to achieve, but it looks as if you want to add stuff to the command line of a program (dialog in this case). For that, you need xargs, unless you want to build the entire command line in advance, which is also possible.
I'm not entirely sure what you are trying to achieve, but it looks as if you want to add stuff to the command line of a program (dialog in this case). For that, you need xargs, unless you want to build the entire command line in advance, which is also possible.
What I am trying to is to just display a menu from my array - get_usb_devices. The utility dialog with --menu option expects two parameters for each item. Here is a simple example of using menu with dialog:
Code:
dialog --clear --title "List USB Devices" \
--menu "Move using [UP] [DOWN} Arrow keys, Hit [ENTER] key to select." 15 50 5 \
1. "usb hard drive"
2. "usb flash drive"
3. "usb cd-rom"
Now instead of the above three items I would like to display the items from my array. Try running the above piece of code and you will see what I am trying to say.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.