Jump to content

read command bash loop


Subspace3

Recommended Posts

Hi all,

Yes I know I'm lame, its been such a long time since I've done any kind of scripting, I'm a cisco kid now. Wondering if any one can help me.

echo -n Enter BSSID:

read name

echo $name >> /tmp/blacklist.txt

Basically wanting that to run multiple times and then move on when the user is finished entering. I know I could just send the values as arguments when running the script (script.sh arg1 arg2 ect( but this way is much nicer.

I'm thinking something like a while loop reading $name and if say "exit" comes up breaking the loop, but not sure on the syntax or if this is the best way as 'exit' would appear in the file also.

thanks for any help

Edited by Subspace3
Link to comment
Share on other sites

Sure! It's pretty simple, just an endless while look with an if statement checking the name variable which breaks it out of the loop.

#!/bin/bash

while true; do
  echo -n Enter BSSID:
  read name
  [[ "$name" == "exit" ]] && {
    echo Exiting.
    break
  } || {
    echo $name >> /tmp/blacklist.txt
    name=""
  }
done

Best Regards,

Sebkinne

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.

  • Recently Browsing   0 members

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