It is currently Mon, 27 Jun 2022 11:57:30 GMT



 
Author Message
 ksh conditional (string match pattern)
Hi,
I want to set up my .profile to use different environment variables
based on machine name. I currently do this with a case statement, ie

MACHINE=`uname -n`
case $MACHINE in
        machine1|machine2)      export VAR=/onepath;;
        other)                  export VAR=/different/path;;
esac

but looking in my Unix in a Nutshell (shameless plug for a great book)
I see that ksh should support the followign conditional test

if [ "$MACHINE" = "machine?" ]
then
        export VAR=/onepath
else
        export VAR=/different/path
fi

This doesn't seem to work for me though - am I missing something here?

I have tried [[]], and also * instead of ? and still don't get the
desired result.

Any help greatly appreciated
Matt Proctor
m...@lyveden.demon.co.uk



 Sun, 28 Jan 2001 03:00:00 GMT   
 ksh conditional (string match pattern)

if [[ $MACHINE = machine? ]]

or, better yet:

if [[ $(uname -n) = machine? ]]

To quote the second argument turns it not into a pattern but a
literal string.  Also, use the [[ ...  ]] form of the ksh conditional
instead of [ ... ], which is there only for backwards compatibility
with older shells. Some older kornshells do not mandate the additional
syntactical quoting nuances when using this older form--such as
never needing to specify dquotes around variable substitutions.

-Brian



 Sun, 18 Mar 2001 03:00:00 GMT   
 
   [ 2 post ] 

Similar Threads

1. ksh pattern matching when pattern is in a variable

2. Pattern matching and extracting the data which matches the pattern

3. Append string to each line if it matches a pattern

4. string pattern matching

5. Pattern matching in ksh

6. How can I pattern-match in ksh?

7. ksh and pattern matching

8. ksh discrepancy on pattern matching

9. KSH Pattern Match Deletions

10. Help: Pattern matching in KSH if statement


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software