Skip to Content.
Sympa Menu

baslinux - Re: [BL] sh conditionals etc

baslinux AT lists.ibiblio.org

Subject: Baslinux mailing list

List archive

Chronological Thread  
  • From: 3aoo-cvfd AT dea.spamcon.org
  • To: baslinux AT lists.ibiblio.org
  • Subject: Re: [BL] sh conditionals etc
  • Date: Mon, 24 May 2004 07:45:45 +1200

Sheldon Isaac wrote:
>
> > if [ `pidof rpciod` > 0 ]
> > then
> > echo FIC mounted
> > PS1="FICon \w> "
> > else
> > echo FIC not mounted
> > PS1="\w> "
> > fi
>
> I'm not understanding how to do tests such as Is this thing
> equal/bigger/smaller, or Is this thing null (whatever that is)
> or Does so-and-so exist
>
> You saw the way I did it with the bash in BL2.1, apparently
> was that a string or numeric comparison of `pidof rpciod`.

`pidof xxxx` simply outputs the process number of xxxx.
For example, try the following:
-----------
pidof kpiod
-----------
You will probably get 4 (kpiod is a kernel process that usually
runs in that position).

Now try this little script:
------------------------
if [ `pidof kpiod` > 0 ]
then echo yes
else echo no
fi
------------------------
It should output yes. If you edit the script and change kpiod
to xxx (or other nonsense), it should output no.

> But I can' t find simple lessons on how to say it so that
> sh will do it.

sh does it just fine. I've just run the above script in BL3.

> I need to know how to do if then else and case and such stuff.

As you can see "if then else" works fine in BL3. So does "case":
-----------------------------------
case `pidof kpiod` in 4) echo yes;;
*) echo no
esac
-----------------------------------
I've just run that script in BL3 too.

> Are there functions like length,

Yes.
------------------
a=apple; length $a
------------------

> as in
> if length(`pidof rpciod`) -gt 0;

This works on BL3:
------------------------
a=apple
if [ `length $a` -gt 0 ]
then echo yes
else echo no
fi
------------------------
However, if $a is null, length treats it like --help and you get
some usage junk.

> or is it length(string(`pidof rpciod`))

length does not use (
There is no string command.

Cheers,
Steven




Archive powered by MHonArc 2.6.24.

Top of Page