Jump to content

Bash Pros


tbstuntz
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...