Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Shortening

0 views
Skip to first unread message

sil

unread,
Nov 20, 2006, 11:19:24 AM11/20/06
to
OS=$( uname|sed -n '1p')

if [ $OS = Linux ]
then
something
else
if [ $OS = FreeBSD ]
then
something
else
if [ $OS = NetBSD ]
then
something
if [ $OS = OpenBSD ]
then
something
fi
fi
fi

I know this can be shorter.. It's a brainfarting Monday

if [ $OS = *BSD ] or so

Radoulov, Dimitre

unread,
Nov 20, 2006, 11:25:55 AM11/20/06
to

"sil" <dsphu...@gmail.com> wrote in message
news:1164039564.1...@j44g2000cwa.googlegroups.com...

Use case:

case "$OS" in
*BSD) ...


Regards
Dimitre


Chris F.A. Johnson

unread,
Nov 20, 2006, 11:31:37 AM11/20/06
to

case `uname` in
Linux*) # do something Linuxy ;;
FreeBSD*) # do something Freeby ;;
NetBSD*) # do something Netty ;;
OpenBSD*) # do something Openly ;;
*) # do something else ;;
esac

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence

bsh

unread,
Nov 21, 2006, 11:21:23 PM11/21/06
to
sil wrote:
> I know this can be shorter.. It's a brainfarting Monday

The shortest it can be made is to use someone else's code.

"config.guess.sh; config.sub.sh"
http://cvs.savannah.gnu.org/viewcvs/config/config/config.{guess,sub}

"archit.sh"
http://www.cs.indiana.edu/~kinzler/home/binp/archit

"opsys.sh"
http://www.cs.indiana.edu/~kinzler/home/binp/opsys

"platform.sh"
in GNU shtools

"whatami.sh"
component of http://www-unix.mcs.anl.gov/systems/software/msys/

"archguess.sh"
http://sourceforge.net/projects/archguess/

and, of limited applicability,

"shtype"
http://shelldorado.com/scripts/cmds/shtype.txt

and my own "whichshell"
http://groups.google.com/group/comp.unix.shell/browse_frm/thread/2bd63afd15f87c43/01513a857080ed64?lnk=st&q=&rnum=1&hl=en#01513a857080ed64

P.S. You may wish to investigate the "canonical" solution: the
autoconf app which "automatically configures shell scripts ... to
adapt ... to many kinds of UNIX-like systems without manual
user intervention."

http://www.gnu.org/software/autoconf/

=Brian

0 new messages