Bash to select panel then specific file in directory


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash to select panel then specific file in directory
# 1  
Bash to select panel then specific file in directory

I am using bash to prompt a user for a choice using: where a "y" response opens a menu with available panels that can be used.

Code:
while true; do
    read -p "Do you want to get coverage of a specific panel?" yn
    case $yn in
        [Yy]* ) menu; break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
done

My question is normally I would use a loop to apply the user selected panel to. However, in this case I can not do that because, there might be 5 files in the directory, but only 1 of those files gets the user selected panel applied to it, the other 4 do not.

For example, say the user selects panel1 and in the directory located at (/user/file/data) that panel1 can be applied to is file1 and file2. How do I allow the user to select which file in the directory to apply panel1 to? Thank you Smilie.

Last edited by cmccabe; 02-24-2016 at 03:05 PM.. Reason: added details
# 2  
You would handle that within your menu function.
Try:
Code:
select file1 in $(cd /user/file/data;ls);do break;done
echo $file1

hth
This User Gave Thanks to sea For This Post:
# 3  
Is this what you mean? Thank you Smilie.

Code:
while true; do
    read -p "Do you want to get coverage of a specific panel?" yn
    case $yn in
        [Yy]* ) menu; select file1 in $(cd /user/file/data;ls);do break;done
                  echo $file1
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
done

# 4  
Quote:
Originally Posted by sea
You would handle that within your menu function.
Try:
Code:
select file1 in $(cd /user/file/data;ls);do break;done
echo $file1

hth
EDIT:
Obviously, instead of echo, do whatever you want/need to do with that selected file1.
This User Gave Thanks to sea For This Post:
# 5  
The user prompt is executed and if "y" is entered then the menu function is called.

Code:
while true; do
    read -p "Do you want to get coverage of a specific panel?" yn
    case $yn in
        [Yy]* ) menu; break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
done

Code:
menu() {
    while true
    do
        printf "\n please make a selection from the MENU \n
        ==================================
        \t 1  Incidental Findings     
  ==================================\n\n"
        printf "\t Your choice: "; read menu_choice

        case "$menu_choice" in
        1) incidental ;; select file1 in $(cd /user/file/data;ls);do break;done
            ......... (whatever command to execute)
        *) printf "\n Invalid choice."; sleep 2 ;;
        esac
    done
}

So if the "incidental" is selected after the ;; is where to add select file1 in $(cd /user/file/data;ls);do break;done ? Thank you Smilie

Last edited by cmccabe; 02-24-2016 at 06:25 PM.. Reason: fixed format
# 6  
Your above example will fail (just like the previous one).
Why do you put code in between cases?

After the ;;, the specific case is closed.
Before the *), no new case is opened.

Keep in mind, ; differs single/multiple commands from each other.
;; defines the end of a specific case of a case-block (from case to esac).

Code:
1) incidental ;; select file1 in $(cd /user/file/data;ls);do break;done
            ......... (whatever command to execute)

Code:
1) incidental ; select file1 in $(cd /user/file/data;ls);do break;done
            ......... (whatever command to execute) ;;

hth, have a good day
This User Gave Thanks to sea For This Post:
# 7  
Thank you very much for your help and have a good day as well Smilie.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #191
Difficulty: Easy
In Python, the tuple data type is immutable and cannot contain mixed types.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to move specific files to directory based on match to file

I am trying to mv each of the .vcf files in the variants folder to the folder in /home/cmccabe/f2 that the .vcf id is found in file. $2 in file will always have the id of a .vcf in the variants folder. The line in blue staring with R_2019 in file up to the -v5.6 will always be an exact match to a... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Create automated scan of specific directory using bash

I am trying to use bash to automate the scan of a specific directory using clamav. Having this in place is a network requirement. The below is an attempt to: 1. count the extensions (.txt, .jpeg) in a directory and write them to a virus-scan.log (section in bold) 2. scan each folder in the... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

Bash to select oldest folder in directory and write to log

In the bash below the oldest folder in a directory is selected. If there are 3folders in the directory /home/cmccabe/Desktop/NGS/test and nothing is done to them (ie. no files deleted, renamed) then the bash correctly identifies f1 as the oldest. However, if something is done to the folder then... (4 Replies)
Discussion started by: cmccabe
4 Replies

4. Shell Programming and Scripting

Bash to list all folders in a specific directory

The below bash is trying to list the folders in a specific directory. It seems close but adds the path to the filename, which basename could strip off I think, but not sure why it writes the text file created? This list of folders in the directory will be used later, but needs to only be the... (5 Replies)
Discussion started by: cmccabe
5 Replies

5. UNIX for Beginners Questions & Answers

Using grep to select specific patterns in text file?

How do I use grep to select words that start with I or O, end in box, and contain at least one letter in between them? the text file mailinfo.txt contains Inbox the Inbox Is a match box Doesn't match INBOX Outbox Outbox1 InbOX Ibox I box If the command works correctly it... (4 Replies)
Discussion started by: steezuschrist96
4 Replies

6. Shell Programming and Scripting

Bash to select text and apply it to a selected file in bash

In the bash below I am asking the user for a panel and reading that into bed. Then asking the user for a file and reading that into file1.Is the grep in bold the correct way to apply the selected panel to the file? I am getting a syntax error. Thank you :) ... (4 Replies)
Discussion started by: cmccabe
4 Replies

7. Shell Programming and Scripting

Bash to select oldest folder in directory automatically and log process

The `bash` below uses the oldest folder in the specified directory and logs it. The goes though an analysis process and creates a log. My problem is that if there are 3 folders in the directory folder1,folder2,folder3, the bash is using folder2 for the analysis eventhough folder1 is the oldest... (0 Replies)
Discussion started by: cmccabe
0 Replies

8. Shell Programming and Scripting

Bash to select and save file in new directory

I am trying to select a file in bash and save it to a directory. The below does run but no selected file is saved. Thank you :). bash # select file printf "please select a file to analyze with entered gene or genes \n" select file in $(cd... (4 Replies)
Discussion started by: cmccabe
4 Replies

9. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

10. Solaris

Limit bash/sh user's access to a specific directory

Hello Team, I have Solaris 10 u6 I have a user test1 using bash that belong to the group staff. I would like to restrict this user to navigate only in his home directory and his subfolders but not not move out to other directories. How can I do it ? Thanks in advance (1 Reply)
Discussion started by: csierra
1 Replies

Featured Tech Videos