tbstuntz Posted November 17, 2010 Share Posted November 17, 2010 I am really new to bash and I can't work this out. Say I wanted to generate a menu with options from an application output. i.e echo "Which folder do you wish to copy?" #list all directories ls -d */ so the current output is Music Videos Documents Downloads But I am trying to turn the output into a menu [1]Music [2]Videos [3]Documents [4]Downloads The idea is to be able to run airodump-ng and then all the ap's will be in a menu and I could select a ap from the menu and use its information in other programs automatically. Hopefully this aint too confusing. thanks Quote Link to comment Share on other sites More sharing options...
Netshroud Posted November 17, 2010 Share Posted November 17, 2010 Don't just copy, look at what I've done and see how it works. (It does all files though, not just directories) #!/bin/bash directories = "`ls -l | ask '{print $9}' | grep -v ^$`" let i=0 for directory in $directories; do echo [${i}] $directory let i=i+1 done Then comes the task of getting user input and responding to it. Quote Link to comment Share on other sites More sharing options...
justapeon Posted November 17, 2010 Share Posted November 17, 2010 Don't just copy, look at what I've done and see how it works. (It does all files though, not just directories) #!/bin/bash directories = "`ls -l | ask '{print $9}' | grep -v ^$`" let i=0 for directory in $directories; do echo [${i}] $directory let i=i+1 done Then comes the task of getting user input and responding to it. That code does not work at least on my system. Quote Link to comment Share on other sites More sharing options...
Netshroud Posted November 18, 2010 Share Posted November 18, 2010 #!/bin/bash directories="`ls -l | awk '{print $9}' | grep -v ^$`" let i=0 for directory in $directories; do echo [${i}] $directory let i=i+1 done Typo and extra spaces. Sorry about that. Quote Link to comment Share on other sites More sharing options...
Jason Cooper Posted November 19, 2010 Share Posted November 19, 2010 Or you could use the select command in bash that does exactly what you are after. e.g. PS3='? ' select d in `ls -d */` do echo $d break done The PS3 variable is what is used to prompt the user for their choice. Also select loops till the loop is broken, which is why we have the break command just before the done. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.