|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
How to use shell var for pattern string at KSH
Hi there, In the following test, how to use shell var for pattern, regular expression. I need to accept pattern at argument, use it to pattern matching at shell script. Test: Code:
#!/bin/ksh # name t.sh exp="a@(a|b)" touch aa ab ac echo "\nTest without variable" echo "---------------------" ls -1 a@(a|b) echo "\nTest with with variable(exp=$exp)" echo "----------------------" ls -1 $exp ###################################### # test ###################################### # chmod 775 t.sh # t.sh ###################################### # test output ###################################### # Test without variable # --------------------- # aa # ab # # Test with with variable(exp=a@(a|b)) # ---------------------- # a@(a|b) not found # <-- probelm ###################################### Last edited by Franklin52; 09-09-2009 at 08:21 AM.. Reason: Please use code tags! |
| Sponsored Links | ||
|
|
|
|||
|
Thanks
eval ls ${exp} may be more efficient than using a new child sh,
such as ksh -c "ls $exp". Radoulov, Much thanks for your help. ![]() |
| Sponsored Links |
|
|
![]() |
| Bookmarks |
| Tags |
| ksh, regexp, variable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to search for a pattern a string? | Leo_NN | UNIX for Dummies Questions & Answers | 12 | 10-16-2008 02:38 PM |
| extract a string after a pattern using sed | gunaah | Shell Programming and Scripting | 1 | 10-11-2008 04:19 PM |
| Compare string to a pattern | jerryte | Shell Programming and Scripting | 2 | 01-25-2008 08:37 PM |
| how to get the last part of a string followed by a pattern | bluemoon1 | Shell Programming and Scripting | 4 | 09-08-2007 12:10 PM |
| how to know if a string contains a certain pattern | Deanne | Shell Programming and Scripting | 11 | 08-09-2007 09:19 PM |