BASH scripting Question - Select loop displaying output
...
|
Store Output of a Command to an Array
Quote:
Code:
#!/bin/bash Code:
echo ${FILES[$Index]} Storing the output of "ls -1" (you can use any other command, say "ls -ltr") command to an array: Code:
FILES=($(ls -1)) Code:
read -p 'Press the Enter/Return Key to Continue...' Modify the above script to suit your other requirements. Cheers! |
That's a while loop still, I would like it to be a select loop
|
Quote:
|
| more does not will not work inside a select loop.
|
The reason I want a select loop is because eventually I will be running another select loop with functions in that. So the first select loop above will choose a file from the list, then the second loop will execute a function within side of that such as delete.
|
Quote:
To make things more complicated, select will print the options in multiple columns at the slightest provocation: Code:
$ select file in $(seq 1 20); do echo $file; done Code:
dialog --fselect ./ $height $width # will make a nice dialog to select a file |
That is what I am working towards something like this:
INPUT1 = $1 INPUT2 = $2 INPUT3 = $3 VAR1 = 0 LENGTH = 0 if [[ INPUT2 == ""]] then while [ VAR1 = 0 ]; do while [ Array.Length > Length ] do select VAR1 in Array:Length:Length:+19 "sort name" "sort size" "sort age" "more" do case quit) exit;; "sort name") ;; "sort size") ;; "sort age") ;; more) ;; *) esac done length=legnth+19 done done select do #commands in a case delete, copy,etc done fi |
So I want to use the select loops to be able to select an item off the list (a file) then run another select loop and select an item off that list such as delete etc.
|
|
I still don't follow. What is wrong with example given by devUnix? To improve on that, it could look like:
Code:
#!/bin/bash |
I mean I understand that its easier don't get me wrong. I am just working on an objective where it has to be select loops. I can do it in while loops, it's I am not use to select loops.
We need to prompt the user for a file, then they need to select it, then prompt them for a command to use, and both those need to be select loops. We can nest then in other loops. |
sigh. Ok, how about something like this then?
Code:
#!/bin/bash Another problem would be if there happened to be files named "previous" or "next" in the current directory. But I'll leave that to you to deal with as an exercise :P |
I am currently on 2 day order with my Army Unit, havn't had to look at it, just printed it and going to look at it at chow.
Thanks for the help though! |
Quote:
|
All times are GMT -5. The time now is 02:46 PM. |