BASHing Visual Basic Out of the Picture
RSS Feed - Comments↴ Author: Jacob Barkdull on Monday, June 28 2010There were small problems getting it to work properly (as this can happen programing anything.) Seeing the code, everything looked like it would work, but it didn't, not ever having much experience with Visual Basic -- I only learned a few things, and they were during my last year using Windows, this was around three years ago) I could only offer a few guesses related to the errors it was throwing. The code reminded me of Python, and the errors reminded me of C++, C#, and Perl mixed together, they were not at all useful.
When they first started working on it, I already had the code layout to accomplish such a task in my head as PHP, but I wasn't quite sure how I would run the PHP code locally on a Windows system let alone print to a local printer using PHP.
That's when it hit me, BASH!
No, nothing bashed me in the head, I am referring to GNU BASH. I knew that it would be an easy task in BASH, a couple variables, a simple "while loop", an "if", and the print command "lpr". Here's what I got:
#!/bin/bash
moddate=$(stat -c %y workdoc.txt)
moddate=${moddate% *}
while [ 1 ]
do
sleep 1
newmoddate=$(stat -c %y workdoc.txt)
newmoddate=${newmoddate% *}
if [ "$newmoddate" != "$moddate" ]
then
lpr workdoc.txt
moddate=$newmoddate
fi
done
moddate=$(stat -c %y workdoc.txt)
moddate=${moddate% *}
while [ 1 ]
do
sleep 1
newmoddate=$(stat -c %y workdoc.txt)
newmoddate=${newmoddate% *}
if [ "$newmoddate" != "$moddate" ]
then
lpr workdoc.txt
moddate=$newmoddate
fi
done
What I noticed was: this is near 50% smaller than Visual Basic's source. And BASH automatically runs in the background of a graphical environment -- unless it's executed from an open graphical terminal (such as gnome-terminal) -- at least in GNOME it works this way.
I'll note that I didn't find a way to use it conveniently on Windows, but it would be easy enough to run the code through SHC and compile the C source code for Windows. Despite the title, I eventually helped finish the program with a simple BATCH script, so both BASH and Visual Basic were out of the picture.
I write about this because I find it interesting, and because it's been a long time since I've written any code that someone might have a real-world or business related use for. So... It's simple! It's fast! Use it if you want :)
Share This:
Tweet
Syndication:

Advertisements:

GNU/Linux systems with software you need already installed!

GNU/Linux Tech
Advertise Here
Partners & Friends:



![[frdm] Support SFLC](http://www.softwarefreedom.org/img/support-sflc.png)
Translations (Google)
Česky ·
简体中文 ·
日本語
Español · العربية · Deutsch
русский · 한국어 · Italiano
Français · Português
GNU/Linux systems with software you need already installed!
GNU/Linux Tech
Advertise Here

Español · العربية · Deutsch
русский · 한국어 · Italiano
Français · Português
What Is This Place?
TildeHash is a website for Tech articles
revolving around Free Software
and Unix/Unix-like operating systems,
written by Jacob Barkdull and various contributors,
respectively. Meaning, Free Software (or Open Source); and
GNU/Linux (or simply
Linux),
BSD, OpenSolaris,
or Haiku; respectively. The main goal
of TildeHash is to be different -- the name alone is a little different
(explanation here) -- but
to do it in a useful way.
TildeHash is about discussing Free Software topics that are beneficial to our community, topics that are largely not discussed nor shown. "Free Software" is also often called "Open Source Software". In practice the requirements are identical, although because the term "open" doesn't call to mind freedom, it misses the point.
List of Articles >>
TildeHash is about discussing Free Software topics that are beneficial to our community, topics that are largely not discussed nor shown. "Free Software" is also often called "Open Source Software". In practice the requirements are identical, although because the term "open" doesn't call to mind freedom, it misses the point.
List of Articles >>
Comments powered by Disqus
