Re: combining the result of processing various commands and setting it in a variable
From: Stephane CHAZELAS (this.address_at_is.invalid)
Date: 11/19/05
- Next message: Janis Papanagnou: "Re: combining the result of processing various commands and setting it in a variable"
- Previous message: Bruce Barnett: "Re: Bug in awk?"
- In reply to: onetitfemme: "Re: combining the result of processing various commands and setting it in a variable"
- Next in thread: Janis Papanagnou: "Re: combining the result of processing various commands and setting it in a variable"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 19 Nov 2005 14:45:03 +0000
2005-11-19, 05:08(-08), onetitfemme:
> _VER="Linux version";
[...]
> _CHKVER=$(dmesg | grep -i "${_VER}");
[...]
> _CHCKVER=`dmesg | grep -i "$_VER"`;
[...]
> _CHCKVER=$(dmesg | grep -iF -- "$_VER");
> echo ${_CHKVER};
[...]
> Now, which of the working versions of the script is the most portable
> one?
>
> The last one as given by Stéphane?
>
> I need for the script to hopefully work on any Unix and Linux
> versions. Right now I am testing it with Linux/Debian/Knoppix
[...]
For that particular value of $_VER all the 3 ones are
equivalent. For any value of $_VER, only the 3rd one is correct.
All those are POSIX conformant. Only the 2nd will work with the
Bourne shell (which is an old shell you sometimes find on very
old systems or on Solaris as /bin/sh). You may find some old
greps that don't recognise -F.
As long as $_VER doesn't contain any ., *, [, ^, or $
characters and don't start with a "-", you can stick with the
second solution.
Otherwise, instead of:
_VER='- $Version: 1.2$'
for instance, you'll have to write it:
_VER='[-] \$Version: 1\.2\$'
_CHCKVER=`dmesg | grep -i "$_VER"`;
You're more likely to have compatibility issues with dmesg, than
with the syntax of the 3rd line, though.
If you want the OS version, note: uname -rs
-- Stéphane
- Next message: Janis Papanagnou: "Re: combining the result of processing various commands and setting it in a variable"
- Previous message: Bruce Barnett: "Re: Bug in awk?"
- In reply to: onetitfemme: "Re: combining the result of processing various commands and setting it in a variable"
- Next in thread: Janis Papanagnou: "Re: combining the result of processing various commands and setting it in a variable"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|