0

I have below script which turns on the tether mode on my intel edison. But when I entered password with space it shows error that argument list is long. Without space it works perfectly fine

#!/usr/bin/env bash

SSID_FILE="/usr/share/apache2/htdocs/userhotspotname.conf"
if [ -s "$SSID_FILE" ]
then
    filename="/usr/share/apache2/htdocs/userhotspotname.conf"
    while IFS= read -r line; do
        if [[ $line == hotspotna* ]] ; then
            name=$(echo $line | grep "hotspotname" | cut -d= -f2)

        fi
        if [[ $line == hotspotpa* ]] ; then
            pass=$(echo $line | grep "hotspotpass" | cut -d= -f2)
            #pass="'${pass}'"
            echo $pass
        fi
        done < "$filename"
        **connmanctl tether wifi on "${name}" ${pass}**
fi

Below is userhotspotname.conf file content

hotspotname=cvg_space
hotspotpass=cgoma  pwd space

Since password is with space connmanctl tether wifi on "${name}" ${pass} This command is failing since it is considering it as 4 arguments. Please help in this if anyone has idea.

10
  • @tripleee I already tried using this but it is not working. I not sure how to use "$*" in my case. Commented Aug 31, 2017 at 11:38
  • Always quote all the things unless you know exactly what you are doing. echo "$pass" Commented Aug 31, 2017 at 11:40
  • Oh, you also need to use cut -f2- to get more than just the second field if there would happen to be an equals sign in the value; or more succinctly, just read the values with sed instead of looping over the lines in the file with while read -r. Commented Aug 31, 2017 at 11:42
  • @tripleee I tried quoting "$pass" as well but it is still not working. I very new to shell. So please excuse if this sily question Commented Aug 31, 2017 at 11:43
  • @tripleee When I am trying to print value of pass it is printing fine. Commented Aug 31, 2017 at 11:45

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.