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.

0andriy
  • 4,183
  • 1
  • 24
  • 37
cgoma
  • 47
  • 2
  • 13
  • @tripleee I already tried using this but it is not working. I not sure how to use "$*" in my case. – cgoma Aug 31 '17 at 11:38
  • *Always* quote *all the things* [unless you know exactly what you are doing](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable). `echo "$pass"` – tripleee Aug 31 '17 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`. – tripleee Aug 31 '17 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 – cgoma Aug 31 '17 at 11:43
  • @tripleee When I am trying to print value of pass it is printing fine. – cgoma Aug 31 '17 at 11:45
  • I added another duplicate which should hopefully help. Several of the solutions in the answers there are severely over-engineered but one of the simple `awk -F= '$1 ~ /^hotspotna/ { $1=""; print }' filename` should work for you. – tripleee Aug 31 '17 at 11:46
  • Then I guess you are not quoting it when you pass it to `connmanctl`. *Always* quote *all the things.* – tripleee Aug 31 '17 at 11:47
  • @tripleee Do you know how to quote argument with space while passing to shell command? – cgoma Aug 31 '17 at 11:49
  • Read the link I posted earlier. `connmanctl tether wifi on "$name" "$pass"` – tripleee Aug 31 '17 at 11:49
  • @tripleee I tried with connmanctl tether wifi on "$name" "$pass" but it still fails – cgoma Aug 31 '17 at 11:55

0 Answers0