hi i am new to bash scripting ..
i created a bunch of folders but only want the folder names with file1. so i go in and make an array to grab the folders the put in a file then i strip the directories so i just have the folder names i need then i would like to make the menu with a selection but how do i case the selections to be dynamic so if i have 7 or 3 file1. it will work as i would like to take the selected file name and then send it as a varible for later use
i have a file structure like this
folder1 has files1.1 files1.2 files1.3 testmyfile thefiletest other
here is my code:
Code:
clear
array=(/mytest/folder1/files1.*)
printf "%s \n" "${array[@]}" >testfile.txt
fileList=$(</mytest/folder1/files1/testfile.txt )
listarry=()
for i in $fileList[@]
do
if [[ "$i" == *"."* ]]; then
splitList=$(echo $i | cut -d"/" -f4)
if [[ ! "$listarry[@]" =~ "$splitList" ]]; then
listarry+=" $splitList"
fi
fi
done
echo "$listarry"
PS3="select number or Q to quit: "
COLUMNS=12
select filename in $listarry; do
if [-n "$filename" ]; then
vim ${filename}
fi
break
done
thanks
lamby22
Last edited by Scrutinizer; 12-14-2017 at 01:59 PM..
Reason: code tags
You say that you have a bunch of directories several of which contain a file named file1. And you say that you want to be able to give bash's select a list of directories that contain a file named file1. But you then go on to say that the directory /mytest/folder1 contains the six files: files1.1, files1.2, files1.3, testmyfile, thefiletest, and other (none of which are named file1) and your code is only looking for files in the directory named /mytest/folder1 with names that start with files1. (including the s and the <period> and not looking for files in any other directory).
If you're looking for files named file1 in several directories, one might have expected you to use:
Code:
array=(/mytest/*/file1)
or (if the files you want are deeper in a file hierarchy):
Code:
array=( $(find /mytest -name file1) )
instead of:
Code:
array=(/mytest/folder1/files1.*)
Please clarify what you are really trying to do.
Last edited by Don Cragun; 12-15-2017 at 12:23 AM..
Reason: Fix typos, highlight misspellings.
hi dan,
sorry i wasn't clear sounded good in my head.
i have a group of files in the directory mytest/folder1 inside that folder are multiple files
i would like to only pull out certain files(files1.*) from folder and list them but the files sometime change i may pull out 3 one time or 7 the next depends on what i am selecting
example (take the files that have files1.* only out
Code:
mytest/folder1/
files1.1
files1.2
files1.3
testmyfile
thefiletest
other
output this time would be this
Code:
1) files1.1
2) files1.2
3) files1.3
Moderator's Comments:
Please use CODE tags when displaying sample input, output, file hierarchies, and code segments as required by the forum rules you agreed to when you joined the UNIX & Linux Forums. Without them leading spaces and tabs and trailing spaces and tabs are discarded completely, and adjacent combinations of other spaces and tabs are all coalesced into a single space.
Last edited by Don Cragun; 12-15-2017 at 02:15 PM..
Reason: Add CODE tags again.
Sorry I seem to be a bit thick - I don't understand your usage of the term "folder" (bunch of) in your post#1. Should you be talking of one single directory /mytest/folder1 containing many files amongst which there are files1.1, files1.2, and files1.3, what keeps you from trying
Code:
cd /mytest/folder1
select FN in $(ls files1*) exit; do echo $FN, $REPLY; done
1) files1.1
2) files1.2
3) files1.3
4) exit
#? 1
files1.1, 1
.
.
.
, and then, if done, cd back to the original working directory?
A lot of my scripting makes use of the 'select' command to create menu driven input. A typical example of how I use it is as:
somevar=''
PS3='Select one: '
while ]; do
select somevar in $(sqlplus -s $dbuser/$dbpw@mydb <<EOF
set echo off feedback off verify off... (7 Replies)
Oracle Linux 5.6 64-bit
Given the below snippet
ORACLE_SID=''
PS3='Select target (test) database being refreshed: '
#
while ]; do
select ORACLE_SID in `egrep -i '^FS|^HR' /etc/oratab |\
awk -F\: '{print $1}'|sort` ; do
if ]; then
echo
echo "Please enter a... (19 Replies)
Hi All,
I need to develop a bash script list “list of files” and able to select if any and set as globe variable in script and use for other function.
I would like to see in menu format.
Example out put
Below are the listed files for database clone
1. Sys.txt
2. abc.txt
3. Ddd.txt... (1 Reply)
I am creating a Select menu with a few options and I would like to create a "better" looking interface than just this:
1) Option 1
2) Option 2
3) Option 3
Instead, I would like something like this:
***********
* Cool Script *
* 1) Option 1 *
* 2) Option 2 *
* 3) Option 3 *... (2 Replies)
Hi,
I am using a select in ksh for a script
#!/bin/ksh
FIRSTLIST='one two three four quit'
PS3='Please select a number: '
select i in $FIRSTLIST ;
do
case $i in
one) print 'this is one' ;;
two) print 'this is 2' ;;
three) print 'this is 3' ;;
four) print... (7 Replies)
Hi All,
I am trying to use the select command & the menu.
below mention is my script
#!/bin/bash
2
3 PS3="Is today your birthday? " #PS3 system variable
4
5 echo "\n"
6
7
8 select menu_selection in YES NO QUIT
9 do
10
11 ... (1 Reply)
Hello everyone.
I am using the select command to build a menu, here is my question:
Is it possible to generate a menu which contains several sections and have a separator between the sections without having a selection number generated in front of the separator?
This is a sample of what I would... (1 Reply)
is there a way I can make the menu list reappear when I use select ?
-----
menulist="Change_title Remove_tag Change_tag Add_line Quit"
select word in $menulist #change_title remove_tag change_tag add_line quit
do
case $word in
# first menu option Change Title
... (9 Replies)
Hi all
is menu driven by SELECT can be a dynamic ?
My requirement is that i want SELECT to be created on run time not predefine . The select should be created as per the no of
words in a file
thanks in advance
rawat (2 Replies)
I having problem when I call this cleanupmenu function within a script. It continuously loops and goes to selection * That wasn't a valid selection. I have to kill it everytime to stop it. What am I doing wrong. I use this function menu in several other scripts and I don't have this problem at... (2 Replies)