scripts

shell scripts
git clone git://git.bitsmanent.org/scripts
Log | Files | Refs | README

commit 480082593de8b654b854884976c70fd519820f8d
parent 5d76aacdbc6a4c73e39af31c063d38b7acd216c8
Author: Claudio Alessi <smoppy@gmail.com>
Date:   Wed,  7 Nov 2018 19:47:00 +0100

[iwpick] Better alias/essid string handling.

Diffstat:
Msrc/iwpick | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/iwpick b/src/iwpick @@ -3,6 +3,8 @@ # Requires: wpa_supplicant, dhclient and the iwconfig suite NETWORKS_FILE=~/.networks +newline=" +" connect() { iface=$1 @@ -37,8 +39,10 @@ pickone() { iface="$1" file="$2" ids=$(iwlist "$iface" scan |grep ESSID |cut -d'"' -f2) - nets=$(cat "$file") + nets="$(cat "$file")" + oifs="$IFS" + IFS="$newline" for net in $nets; do essid="$(echo "$net" |cut -d: -f2)" for id in $ids; do @@ -48,6 +52,7 @@ pickone() { fi done done + IFS="$oifs" } usage() { @@ -92,13 +97,13 @@ main() { fi [ -z "$alias" -a -z "$essid" ] && usage if [ -n "$alias" ]; then - s="$(sed -n /^${alias}:/p $file |cut -d: -f2-3)" + s="$(sed -n "/^${alias}:/p" "$file" |cut -d: -f2-3)" essid="$(echo $s |cut -d: -f1)" [ -z "$essid" ] && die "alias '${alias}' not found" key="$(echo $s |cut -sd: -f2)" else # Check the networks file to get a key - key="$(sed -n /:${essid}:/p $file |cut -d: -f3)" + key="$(sed -n "/:${essid}:/p" "$file" |cut -d: -f3)" fi echo "Connecting to ${essid}..."