bash condition if OS ?
Chris F.A. Johnson
c.f.a.johnson-bJEeYj9oJeDQT0dZR+AlfA at public.gmane.org
Wed Apr 7 15:37:54 UTC 2004
On Wed, 7 Apr 2004, Lloyd Budd wrote:
> Hi,
>
> I am trying to combine some of my '.bash_profile's and '.bashrc's from
> various OSs into one file of each. I have condition on hostname, but
> would like to generalize some parts on OS. $OSTYPE is useful, though
> some OSs have the annoying habit of including version # in OSTYPE. Is
> there a better variable to use? Short of using an external prog I
> cannot seem to figure out how to use Bash's reg exp to check for
> substring at beginning of the string. ?
Bash's parameter exapnsion can remove prefixes and suffixes using
pattern matching. To remove from the first digit to the end:
OS=${OSTYPE%%[0-9]*}
Or use uname -s.
--
Chris F.A. Johnson http://cfaj.freeshell.org
=================================================================
Everything in moderation -- including moderation
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list