LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-14-2021, 01:39 PM   #16
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025

Cruising through, seeing this old thread, and thinking that the code can be made much cleaner and shorter.

Code:
mapfile -t inputlist < stations.txt

for i in "${!inputlist[@]}"; do

    outputlist+=( "$((i+1))" "${inputlist[i]}" )

done

whiptail --title "Choose radio station:" --menu "select your choice" 16 78 5 "${outputlist[@]}"
Assuming I understand the requirements right, this should give you an array with tag-item pairs, and index numbers adjusted properly. At least it seems to work for me.


Also, from the OP:

Code:
By the way i'm using zsh, but i guess it doesn't matter because i include #!/bin/bash in the first line of the script. Is this true?
Yes, this is true. The shebang line at the top of a script tells your system which interpreter to process it with. The shell you run it from has no effect, other than acting as the script launcher.


Edit: One small change to simplify it even more:

Code:
mapfile -t -O 1 inputlist < stations.txt

for i in "${!inputlist[@]}"; do

    outputlist+=( "$i" "${inputlist[i]}" )

done

whiptail --title "Choose radio station:" --menu "select your choice" 16 78 5 "${outputlist[@]}"
The -O option to mapfile/readarray will start the array count at 1 instead of 0.

Last edited by David the H.; 10-14-2021 at 01:45 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Converting Script from Linux (GNU) Bash 4 to Solaris Bash 2.05 - Any cheat sheet? oly_r Solaris / OpenSolaris 6 05-03-2013 09:25 AM
is it possible to use multiple inputbox with whiptail kankan55 Linux - Software 0 02-16-2013 06:44 AM
whiptail with multiple inputbox kankan55 Linux - Newbie 1 02-14-2013 12:25 PM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 09:56 AM
Alsaconf needs 'whiptail' or 'dialog' Exeis Linux - Software 3 08-27-2008 10:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration