Sponsored Content
Top Forums Shell Programming and Scripting Dynamic Bash Dialog from directory listing Post 303021070 by shrout1 on Friday 3rd of August 2018 12:17:50 PM
Old 08-03-2018
Ok! A coworker helped me noodle this through; turns out the input required for dialog is rather odd...

Code:
#! /bin/bash
#usage: Dynamic_Menu.bash /home/user/target_directory
declare -a array

i=1 #Index counter for adding to array
j=1 #Option menu value generator

while read line
do		
#Dynamic dialogs require an array that has a staggered structure
#array[1]=1
#array[2]=First_Menu_Option
#array[3]=2
#array[4]=Second_Menu_Option

	array[ $i ]=$j
	(( j++ ))
	array[ ($i + 1) ]=$line
        (( i=($i+2) ))
	
done < <(find $1 -type f) #consume file path provided as argument

##uncomment for debug
#printf '%s\n' "${array[@]}"
#read -rsp "Press any key to continue..." -n1 key

#Build the menu with dynamic content
TERMINAL=$(tty) #Gather current terminal session for appropriate redirection
HEIGHT=20
WIDTH=76
CHOICE_HEIGHT=16
BACKTITLE="Back_Title"
TITLE="Dynamic Dialog"
MENU="Choose a file:"

CHOICE=$(dialog --clear \
                --backtitle "$BACKTITLE" \
                --title "$TITLE" \
                --menu "$MENU" \
                $HEIGHT $WIDTH $CHOICE_HEIGHT \
                "${array[@]}" \
                2>&1 >$TERMINAL)

I haven't fully debugged this yet, but from a directory with less than 10 files it's working!

Last edited by shrout1; 08-03-2018 at 05:10 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies

2. UNIX for Dummies Questions & Answers

Timestamp in directory listing

Hi, I need a help. I want to see all the files in the directory with the Time Stamp. I use the following command. $ls -lt This displays the files with time stamp, but not all the files. Only last few months, the files are displayed with timestamp, the old files are only have dates. ... (2 Replies)
Discussion started by: vijashok
2 Replies

3. UNIX for Dummies Questions & Answers

Full Directory Listing...

Is there a way of listing everything under a directory. So for example if you wanted to know everything under the USR directory you would get all the sub directories and files in those directories as well as the file directly under the USR directory. I would imagine that you could do this... (5 Replies)
Discussion started by: B14speedfreak
5 Replies

4. UNIX for Dummies Questions & Answers

How can i get directory listing?

Hai friends is there any command in unix that display only directories... (I have 5 directories in my home directory, and i also have some files along with directories...But when i tried to show the directory listing using the command ls -d i wasn't presented by the directory listing...Please... (2 Replies)
Discussion started by: haisubbu
2 Replies

5. Shell Programming and Scripting

Unix / Linux Dialog Utility - how to open 2+ more dialog windows ?

Hi, example of Unix / Linux dialog utility is below. I am going to use dialog as simple GUI for testing of a modem. So I need to combine some dialog boxes into one. I need to have input box, output box, info box, dialog box, radiobox as in any standard program with graphical user... (2 Replies)
Discussion started by: jack2
2 Replies

6. Shell Programming and Scripting

Directory Listing Help

i have searched through this site and have found some useful information but i'm struggling with one thing. In my script i am created a start and end file so I can get a listing of the files within those two files. However I want to exclude any sub-directories in this listing. Below are the... (8 Replies)
Discussion started by: J-DUB
8 Replies

7. Shell Programming and Scripting

Directory listing

Hi, I have a directory with a bunch of files say around 150K. I want the directory's path and the filenames printed to a text file. Example: If I am in the directory /path/test and the files in this directory are My output file should be like this Thanks in advance ----------... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

8. Homework & Coursework Questions

Listing the files in a directory

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: A script that takes any number of directories as command line arguments and then lists the contents of each of... (3 Replies)
Discussion started by: Phaneendra G
3 Replies

9. Shell Programming and Scripting

Dynamic variable name in bash

Hello, I'm trying to build a small script to store a command into a dynamic variable, and I have trouble assigning the variable. #!/bin/bash declare -a var1array=("value1" "value2" "value3") var1arraylength=${#var1array} for (( i=1; i<${var1arraylength}+1; i++ )); do mkdir... (7 Replies)
Discussion started by: alex2005
7 Replies

10. Shell Programming and Scripting

Require input in bash dialog box

Hello. Any help would be greatly appreciated. Right now I have the following input box that works fine and well, however I would like to wrap this is a loop that requires input. Right now the script will happily continue on if the user just hits enter. I'd like to require a minimum of a 5... (5 Replies)
Discussion started by: woodson2
5 Replies
ARRAY_KEYS(3)								 1							     ARRAY_KEYS(3)

array_keys - Return all the keys or a subset of the keys of an array

SYNOPSIS
array array_keys (array $array, [mixed $search_value], [bool $strict = false]) DESCRIPTION
array_keys(3) returns the keys, numeric and string, from the $array. If the optional $search_value is specified, then only the keys for that value are returned. Otherwise, all the keys from the $array are returned. PARAMETERS
o $array - An array containing keys to return. o $search_value - If specified, then only keys containing these values are returned. o $strict - Determines if strict comparison (===) should be used during the search. RETURN VALUES
Returns an array of all the keys in $array. EXAMPLES
Example #1 array_keys(3) example <?php $array = array(0 => 100, "color" => "red"); print_r(array_keys($array)); $array = array("blue", "red", "green", "blue", "blue"); print_r(array_keys($array, "blue")); $array = array("color" => array("blue", "red", "green"), "size" => array("small", "medium", "large")); print_r(array_keys($array)); ?> The above example will output: Array ( [0] => 0 [1] => color ) Array ( [0] => 0 [1] => 3 [2] => 4 ) Array ( [0] => color [1] => size ) SEE ALSO
array_values(3), array_key_exists(3), array_search(3). PHP Documentation Group ARRAY_KEYS(3)
All times are GMT -4. The time now is 08:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy