Re: OT: How to match a substring?
On Wed, Jan 14, 2004 at 06:14:45PM +0000, Colin Watson wrote:
} On Wed, Jan 14, 2004 at 11:59:12AM -0600, Kent West wrote:
} > I need to run a test in a .bashrc startup script to see whether the
} > machine the user is logging onto is a Solaris or a Linux box (the /home
} > directory is shared between the two, and paths need to be modified
} > according to which OS is being logged into).
} >
} > Something like this:
} >
} > if {the first word of "uname -a" is Linux}
}
} Why not just use 'uname', which prints Linux on Linux and SunOS on
} Solaris?
A good point.
} In general, try either:
}
} if [ "`uname -a | sed -e 's/ .*//'`" = Linux ]
}
} (fairly straightforward) or:
}
} UNAME_A="`uname -a`"
} if [ "${UNAME_A%% *}" = Linux ]
}
} (match trailing portion of variable against shell pattern ' *').
Icky!
if expr "`uname -a`" : 'Linux ' > /dev/null
[...]
} Cheers,
} Colin Watson [cjwatson@flatline.org.uk]
--Greg
Reply to: