简体   繁体   中英

bash script to create a menu from a random list of files

I have a python script which creates a certain amount of files (could be different per environment). from that script i want to create a bash script that will create a menu from that list of files.

I am using the following :

#!/bin/bash
files=$(ls -lh /home/admin/output | grep txt | awk '{print $9}' | sed -n '1!p')
PS3="Pick an Object:"
select devnum in $files; do
     line=$REPLY
     break
done

it works , however i don't know how to assign an action for each option.

for example :

1) object1
2) object2

how do i assign an action to each command? basically i want to execute # vi {file name from menu} for each of the menu options.

You stored the result in $devnum , so just run

vi "$devnum"

below done .

BTW, are you sure devnum is the correct variable name?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM