James Melin writes:
>Looks to me that /etc/mtab contains the most complete information.
>The only thing it doesn't show is swap and the values of fs_freq and
>fs_passno (those last two numbers in the fstab) and that can be figured out
>by rule vs actual. root getting 1 1 the rest getting 1 2 and the thigns
>like sysfs and proc by rule are 0 0.
>
>Are there things like compound variables in the bash shell? Kinda like stem
>variables in rexx ? Something that can be declared and indexed through so
>that var.1 = /dev/dasda var.2 = {mountpoint} var.3 = fs type and so on?
>
>If that's possible in the bash shell then the administrivia of creating the
>script is pretty simple. I just have never seen compound variables in a
>bash shell script, so I'm not sure and someone walked off with my book.
The Bash shell has Array Variables, but (like Rick) I never use them
because I want my scripts to be portable. Here's the "standard" way to
read space-separated fields from a file in the shell, using /etc/mtab as
the example:
while read Device MountPoint FsType FsOptions junk
do # Process one line using the above variables.
...
done < /etc/mtab
The "read" built-in command reads one line from its standard input, breaks
it at whitespace, and assigns each field to the variables whose names are
given as arguments. If there are more fields than arguments, the last
variable named gets all the remaining fields. In this case, last two
fields of /etc/mtab lines (which are always zeros) get assigned to "junk".
Notice that /etc/mtab is made to be the standard input of the
"while" loop, so that it is opened once for the loop. Had we made it be
the standard input of the "read" command, like so:
# This does not work:
while read Device MountPoint FsType FsOptions junk < /etc/mtab
...
then it would repeatedly read the first line of that file forever because
the file would be opened and closed at each invocation of "read". The
"read" command returns non-zero on EOF, which terminates the "while" loop.
Stem variables would be nice because they provide a way of relating the
variables together. The shell way of doing that is to using some prefix as
a naming convention, for example:
while read MTAB_Device MTAB_MountPoint MTAB_FsType MTAB_FsOptions junk
That at least gives you the namespace feature of stems, but none of the
meta-operations on the stem itself. You could probably write some shell
functions to implement those. If I could remember what I learned of REXX
back in the Amiga days, I'l take a stab at that, but I've forgotten most of
what stems can do. Use it or lose it! :-)
- MacK.
-----
Edmund R. MacKenty
Software Architect
Rocket Software, Inc.
Newton, MA USA
----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390