Re: [SLUG] Difficulty level for a beginner?

From: Paul M Foster (paulf@quillandmouse.com)
Date: Sat Mar 12 2005 - 01:13:05 EST


On Fri, Mar 11, 2005 at 10:32:20PM -0500, 404 wrote:

> As you can see from my last post, I want to learn to code. I have been
> using bash scripts to do stuff on my system but I would like to be able
> to code it to an actual program. Example:
>
> #!/bin/bash
> CAT=/bin/cat
> ECHO=/bin/echo
> GREP=/bin/grep
>
> $ECHO "[------- Battery Info ---------]"
> $CAT /proc/omnibook/battery | $GREP Stat
> $CAT /proc/omnibook/battery | $GREP Gau
> $CAT /proc/omnibook/ac
> $ECHO "[------- Fan and Temp ---------]"
> $CAT /proc/omnibook/temperature
> $CAT /proc/omnibook/fan
> $ECHO "[------------------------------]"
>
>
> This is a script I use to check my battery and temp on my laptop. The
> output is:
>
> matt@slacker:~> sysinf
> [------- Battery Info ---------]
> Status: charged
> Gauge: 100 %
> AC on-line
> [------- Fan and Temp ---------]
> CPU temperature: 58 C
> Fan is off
> [------------------------------]
>
> Am I digging in too deep for just starting? I have been reading over the
> online examples and plan on getting a few books next week. I just wanted
> to know if my plans for what I want to do are too much for someone just
> starting ;-p
>

This is a pretty simple script for doing some simple things. It's well
executed and it works. You can't ask for more.

I'd make a couple of comments. First setting $CAT et all to fixed values
is okay, but has a liability. If you're ever on a different machine with
a different distro, you may find things moved (well, maybe not with
these particular commands). Better to do something like:

CAT=`which cat`

The which command finds where something is on your system, and the
backticks (`) allow its execution.

Personally, I never do this. Rather than setting a $CAT variable, I just
use cat, like:

cat /proc/omnibook/ac

If a user is running this and the paths to these executables aren't in
their personal path, they have a bigger problems.

Anyway, you're doing great. Just keep at it. (BTW, you can do the above
script actions in C as well, though it's _far_ more complicated.)

Paul

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:34:22 EDT