-1

I found this

channel_map = {
    "2412" : 1,
    "2417" : 2,
    "2422" : 3,
    "2427" : 4,
    "2432" : 5,
    "2437" : 6,
    "2442" : 7,
    "2447" : 8,
    "2452" : 9,
    "2457" : 10,
    "2462" : 11,
    "2467" : 12,
    "2472" : 13,
    "2484" : 14
}

how do i convert this, so I can use this in a bash script?

I would like to define

$CHANNEL=11

and the script should use the right frequency.

the command I use is for example:

iw dev wlan0 ibss join $ESSID 2412 HT40+ fixed-freq $CELLID
2
  • 1
    What is the underlying use case here? Every linux command I can find will take the channel number directly, and so use the correct frequency without you needing to convert. What does your script do?
    – Paul
    Dec 11, 2012 at 20:25
  • I edited the title to clarify my subject
    – rubo77
    Jun 5, 2014 at 5:51

3 Answers 3

1

I believe that the answer rubo77 is looking for is:

#!/bin/sh –
channel_map[1]=2412
channel_map[2]=2417
channel_map[3]=2422
channel_map[4]=2427
channel_map[5]=2432
channel_map[6]=2437
channel_map[7]=2442
channel_map[8]=2447
channel_map[9]=2452
channel_map[10]=2457
channel_map[11]=2462
channel_map[12]=2467
channel_map[13]=2472
channel_map[14]=2484

channel=11
echo ${channel_map[$channel]}

A more compact way of doing it:

#!/bin/bash
channel_map=(XYZZY 2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 \
                   2462 2467 2472 2484)

channel=11
echo ${channel_map[$channel]}

channel_map is an array. The XYZZY is a placeholder; it will be assigned to channel_map[0].

2
  • this doesen't work anymore
    – rubo77
    Dec 12, 2012 at 22:24
  • I edited the compact way, now it works
    – rubo77
    Dec 14, 2012 at 15:43
1

if you're just looking to pull the corresponding number from that file, try:

awk -v chan=$CHANNEL '{if($3 ~ chan","){gsub("\"","",$1);print $1}}' map

where map is your input file, and $CHANNEL is set to the channel you're looking up.

1
  • this works for a file too
    – rubo77
    Dec 12, 2012 at 9:46
0

Not sure of your full implementation, but as a quick way to get it accomplished.. Though as @Paul said - most I know of take the channel number rather than Frequency:

#!/bin/bash

channel=${1:-"6"}   # Channel will equal the command line argument, default to "6" if empty.
let channel-=1      # This lets you specify 1 - 14 instead of the 0-13 base of an array

freq=(2412 2417 2422 nnnn)  # The channel values, 1-14

echo ${freq[${channel}]}

Be sure to save it as whatever.sh and chmod +x whatever.sh. Then you can just type ./whatever.sh 4 (from the same directory) and the above will echo 2427

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .