Find the answer to your Linux question:
Results 1 to 4 of 4
The variable OUTPUT remains contniues to be tied to ${6} even when there are 8 command line arguments given. The if statements sould reset OUTPUT to ${7} and FREQUENCY to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Dec 2010
    Posts
    122

    bash, command line arguments


    The variable OUTPUT remains contniues to be tied to ${6} even when there are 8 command line arguments given. The if statements sould reset OUTPUT to ${7} and FREQUENCY to ${6} but it will not. I need this script to configure dummy config file for radio bridges and access points. It works fine with the bridges but when I run it for the APs and I need the extra FREQUENCY variable it doesn't work, OUTPUT continues to be ${6}. Any ideas?

    Code:
    #/bin/bash
    #
    # example: ./configure input-file, SSID, IP, device-name, gateway, frequency, output-file
    #
    FILE=${1}
    SSID=${2}
    IP=${3}
    DEVICE=${4}
    GATEWAY=${5}
    FREQUENCY=""
    OUTPUT=${6}
    
    if [[ ${#} -eq 8 ]]; then # {
            FREQUENCY=${6}
            OUTPUT=${7}
    fi
    sed -e "s/\(empty-ssid\).*/${SSID}/g"      \
        -e "s/192\.168\.1\.20$/${IP}/g"        \
        -e "s/\(NanoBridge M.\)/${DEVICE}/g"   \
        -e "s/empty-frequency/${FREQUENCY}/g"  \
        -e "s/\(192\.168\.1\.1\).*/${GATEWAY}/g" ${FILE} > ${OUTPUT}
    #END#

  2. #2
    Just Joined!
    Join Date
    Aug 2012
    Posts
    31
    I just ran your script (excluding the sed line) and it seems to work.

    Are you sure you're actually putting 8 arguments in the line? Your example only shows 7.

    Also, I'm not sure you intend to separate the arguments with commas

  3. #3
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    237
    hi,

    Code:
    $ myFunc(){ one="$1" two="$2" three="$3" four="$4" five="$5" ; (($#==8)) && six="$6" seven="$7" || seven="$6"; echo "seven = $seven";}
    $ myFunc 1 2 3 4 5 6 7 8
    seven = 7
    $ myFunc 1 2 3 4 5 6 7
    seven = 6

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    673
    How many different threads do you need for the same program???? This is at least the third one for this program.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •