Virtual COM port on Linux
Stuart Jansen
sjansen at buscaluz.org
Mon Mar 15 14:09:17 MDT 2010
On Mon, 2010-03-15 at 13:58 -0600, Dave Smith wrote:
> Andrew McNabb wrote:
> > This is exactly why I only use shell scripts for very simple tasks. :)
>
> Well, I got it to work, and I learned something about command line
> argument parsing in the process. Here's what I ended up with, and I
> looked over it, and it was good:
>
> # cat reboot-cable-modem
> #!/bin/bash
> device=/dev/ttyUSB0
> printf '\xFF\x01\x01' >$device # Power off
> sleep 10
> printf '\xFF\x01\x00' >$device # Power on
commit 6ec863c7e6ff94b59b01a16459f04de41fba4e86
Author: Stuart Jansen <sjansen at buscaluz.org>
Date: Mon Mar 15 14:07:36 2010 -0600
Converted reboot-cable-modem to use more idiomatic Bash
* Don't write Perl like C, and don't write Bash like Python.
- Uppercase variable names
- Plenty of whitespace
* Stuarts Rule of Shell Variables: Always quote variable
unless you have a very, very good reason not to.
#!/bin/bash
DELAY=10
DEVICE="/dev/ttyUSB0"
printf '\xFF\x01\x01' > "$DEVICE" # Power off
sleep "$DELAY"
printf '\xFF\x01\x00' > "$DEVICE" # Power on
--
"XML is like violence: if it doesn't solve your problem, you aren't
using enough of it." - Chris Maden
More information about the PLUG
mailing list