1

I have a bash script that places the gsm modem connection name in a variable:

name=$(nmcli -f NAME, TYPE c | grep gsm | grep -oP '.*(?=gsm)')

echo $name gives me "Provider connection".

However, when I use $name to bring the interface up I get the following:

nmcli -t con up id "$name" 

results in "Error: Unknown connection: Provider connection .".

I've tried using ${name} as well and to try and find where the period is coming from I used "($name)" which results in "Error: Unknown connection: (Provider connection )." Also tried writing the connection name to a file an then reading that into a variable but no luck there.

Anybody know where that trailing period/dot comes from?

fedorqui
  • 275,237
  • 103
  • 548
  • 598
Andre
  • 11
  • 2

2 Answers2

0

EDIT:

Ok, I'll call it. I think this is a whitespace issue, not a trailing period.

In this case, you should preprocess the variable before using it:

name="$(echo -e "${name}" | sed -e 's/[[:space:]]*$//')"

nmcli -t con up id "$name"

This will remove only trailing white space, without affecting the actual string.

enter image description here I hope this helps ;-)

asimovwasright
  • 838
  • 1
  • 11
  • 28
-1

Whitespace removal solved this issue. Removed with sed.

name=$(nmcli -f NAME, TYPE c | grep gsm | grep -oP '.(?=gsm)' | sed -e 's/[[:space:]]$//')"

Andre
  • 11
  • 2