Author Topic: Using ! in bash and bash script almost got the better of me, problem  (Read 912 times)

Online wedgetail

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 2428
  • Any Bugs in site?
The thread  trying to get a Sierra 320U Wireless Modem on line using PCLOS have turned out to be a challenge.  The modem is very impressive, with good connection 25 Mb/s with reports of 60 Mb/s when using directIP connection, I got hooked.  This is in Australia.

AS got the software going for the poster and when I realised there AT commands in this I suddenly took notice.  I have spent a lot of time on older Landline modems and configurations and good knowledge of AT commands, but this was before they got expanded with FAX, VOIP and Wireless and ??. Anyway what could be so different.

For other distros the Whirlpool Aussi forum had already proved it could be done, all credit to those tenacious chaps.

Until the modem gets integrated into the kernel it just needs to be coaxed along with AT commands and scripting will ease the burden.

Here is a hurdle that almost stopped me, following AT command needs to be used:

Code: [Select]
AT!SCACT=1,2
In konsole the full command sequence we are using:

[gert@KDE-mini-Cprog ~]$ echo -e "AT!SCACT=1,2\r "
bash: !SCACT=1,2\r: event not found
[gert@KDE-mini-Cprog ~]$

From what I can see ! is special character here and breaks up the line as shown.

This seems to work

[gert@KDE-mini-Cprog ~]$ echo -e "AT\041SCACT=1,2\r "
[gert@KDE-mini-Cprog ~]$

What I would like to know how is the ! to be dealt with are there any options?

The reason my solution fails later when an attempt to introduce su in the play.



32 bit: KDE (older) & various KDE-mini, ASUSTek P5P41D Rev X.0x, BIOS AMI0207 07/21/2009, "Pentium(R) Dual-Core CPU E5300 @ 2.60GHz", nVidia GeForce 9600 GT, 2x1GB Seagate Technology 1000528AS HDD
TV CompuPro VideoMate Vista E700 (not working in Linux), Acer X243HD LCD Screen

Offline djohnston

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6227
  • I don't do Windows

From what I can see ! is special character here and breaks up the line as shown.

This seems to work

[gert@KDE-mini-Cprog ~]$ echo -e "AT\041SCACT=1,2\r "
[gert@KDE-mini-Cprog ~]$

What I would like to know how is the ! to be dealt with are there any options?


AS's option is the one to be used. The \041 is the octal equivalent of an ASCII ! character.

Look here in the Printable Characters section.
Bare metal                           VBox
AMD Athlon 7750 Dual-Core    Single core
4GiB RAM                              1GiB RAM
nVidia GeForce FX 5200          64MB video
LXDE 32bit                            KDE 64bit

Registered Linux User #416378

Offline apavloma

  • New Friend
  • *
  • Posts: 6
Bash "looks inside" double quotes and will try to expand variables etc.

Bash will not "look inside" single quotes.

Try this instead:

echo -e 'AT!SCACT=1,2\r '

Works for me.

Online wedgetail

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 2428
  • Any Bugs in site?
apavloma
Thank you very much, at one stage I thought of single quotes but since I was copying from lines that seemed to work for others I forgot about the single quotes again. You have saved me some worries.   ;D
« Last Edit: March 10, 2012, 02:54:39 AM by wedgetail »
32 bit: KDE (older) & various KDE-mini, ASUSTek P5P41D Rev X.0x, BIOS AMI0207 07/21/2009, "Pentium(R) Dual-Core CPU E5300 @ 2.60GHz", nVidia GeForce 9600 GT, 2x1GB Seagate Technology 1000528AS HDD
TV CompuPro VideoMate Vista E700 (not working in Linux), Acer X243HD LCD Screen

Online wedgetail

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 2428
  • Any Bugs in site?
The modem control strings I was trying to use was copied from roughly here, those people work with another distro where sudo used:

http://forums.whirlpool.net.au/forum-replies.cfm?r=33180496#r33180496

Below puts the modem to sleep with AT+CFUN=0

Quote
#!/bin/sh
sudo echo -e "AT+CFUN=0\r" > /dev/ttyUSB2


Then AS suggested testing following, here instead og going to sleep, this a form of activation of the account on the SIM card to go to the net. The basis of the connect.sh script.

Quote
#!/bin/sh
su -c "echo -e "AT!SCACT=1,2\r" > /dev/ttyUSB2"


My initial understanding was, that using sudo or in pclos case using su was so in case a normal user was trying to connect but did not have the right permissions, then the su would overcome obstacle. In the case of only a single user having access to the modem I am in favour of having the permissions to ttyUSBx right, then no need for su in the script.

When the script failed I started breaking down the line. Below revealed the problem with using double quotes (") or single quotes (') which I fumbled into solving by using \041 instead of !, while this works you need to understand ACII/hex things, a bit heavy and would really test normal users I think.  

Quote
[gert@KDE-mini-Cprog ~]$ echo -e "AT\041SCACT=1,2\r"
AT!SCACT=1,2
[gert@KDE-mini-Cprog ~]$


Having found that following works fine in pclos, the use of the ! is recovered

Quote
[gert@KDE-mini-Cprog ~]$ echo -e 'AT!SCACT=1,2\r'
AT!SCACT=1,2
[gert@KDE-mini-Cprog ~]$


I got curious and tried without thinking hard enough to run:

Quote
su -c "echo -e 'AT!SCACT=1,2\r'"


No permutation of quotes and few other mods gave a result.  Finally I came to the conclusion that part of the problem might be that su - is an operator that ought to call admin password.

Quote
[gert@KDE-mini-Cprog ~]$ su -c "echo -e 'AT!SCACT=1,2\r'"
bash: !SCACT=1,2\r'": event not found
[gert@KDE-mini-Cprog ~]$


To make my life harder, I made some tests of shorter combinations and I did get asked for password, the full line though never got to a stage where it could be tested on the modem.  I don't recall if I was in another KDE-mini at the time (I do a bit of skipping between similar KDE-mini versions ) but the present KDE-mini shows no sign of asking for password, only if I use su -

My question: is there something fundamentally wrong with the concept of a command line string like above   ;D
« Last Edit: March 10, 2012, 06:51:15 PM by wedgetail »
32 bit: KDE (older) & various KDE-mini, ASUSTek P5P41D Rev X.0x, BIOS AMI0207 07/21/2009, "Pentium(R) Dual-Core CPU E5300 @ 2.60GHz", nVidia GeForce 9600 GT, 2x1GB Seagate Technology 1000528AS HDD
TV CompuPro VideoMate Vista E700 (not working in Linux), Acer X243HD LCD Screen