|
Home > Archive > Unix Shell > November 2006 > Shortening
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| 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 2006-11-20, 1:18 pm |
|
"sil" <dsphunxion@gmail.com> wrote in message
news:1164039564.144862.140350@j44g2000cwa.googlegroups.com...
> 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
Use case:
case "$OS" in
*BSD) ...
Regards
Dimitre
| |
| Chris F.A. Johnson 2006-11-20, 1:18 pm |
| On 2006-11-20, sil wrote:
> 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
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
| |
|
|
|
|
|