In the code below how do I get sed's find and replace value to cary over into the output that gets redirected to the .txt file at the end? Everything else gets replaced but everything in the if statement gets left behind.

# example: ./configure input-file, SSID, IP, device-name, gateway, frequency
#
#
FILE=${1}
SSID=${2}
IP=${3}
DEVICE=${4}
GATEWAY=${5}

if [[ ${#} == 5 ]]; then # {
        FREQUENCY=${6}
        sed -e "s/\(empty-frequency\)/${FREQUENCY}/g" 
fi 
sed -e "s/\(empty-ssid\).*/${SSID}/g"                   \
    -e "s/192\.168\.1\.20$/${IP}/g"                     \
    -e "s/\(NanoBridge M.\)/${DEVICE}/g"                \
    -e "s/\(192\.168\.1\.1\).*/${GATEWAY}/g" ${FILE} > /home/garrett/Desktop/NEW-CONFIG.txt
#END#

What if, on line 12, you redirect the output to your file...

sed -e "s/\(empty-frequency\)/${FREQUENCY}/g" > /home/garrett/Desktop/NEW-CONFIG.txt

And then on line 17, append to the same file, using '>>' instead of '>'. Does this solve your problem?

Thanks, that might work. Since then I've altered just a little bit. Now I'm getting this when the script runs on a bridge configure file rather than an AP, where it doesn't use the frequency variable. ->

./configure.sh: line 16: ${OUTPUT}: ambiguous redirect

For this 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=${7}

if [[ "${#} -eq 8" ]]; then # {
    FREQUENCY=${6}
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#

Any ideas now. I'm going to try your thing too.

I think everything else is okay but I have just discovered that my if statement is executing no matter what. Can anyone tell me why?

if [[ "${#} -eq 8" ]]; then # {
    FREQUENCY=${6}
    OUTPUT=${7}
fi

I am running the program with only 6 command line arguments, well 7 if you count ${0} (the name of the script) but it's executing it anyway.

$ ./configure.sh ../system-2.4-BR.cfg MySSID newIP MyNano TheGate New-2.4-BR.cfg

I think you have a little error in the script. You have put the whole expression in quotes while you should have done it something like this:

"${#}" -eq "8"

I believe the "# {" at end of if statement is taken as a comment by shell.