Korn pattern-list with a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Korn pattern-list with a variable
# 1  
Old 03-26-2008
Korn pattern-list with a variable

I am trying to use a pattern-list match in korn shell using a variable and it always seems to regard the pattern-list as a literal:

Using the directory names explicitly in the pattern-list works fine:
ls @(test|test1)/test.txt

and returns:
test/test.txt

Trying to use a variable for this purpose fails:
export patternList=test\|test1
ls @(${patternList})/text.txt

and returns:
@(test|test1)/text.txt: No such file or directory

I tried to interpret the way paths are dealt with in the ksh man page, but failed to understand it properly which is probably why I don't understand why this doesn't work. Can someone tell me how to make this work or why it does not work?
# 2  
Old 03-26-2008
It does not work because shell performes substitution only onetime. (Why - it is another question and I do not know it.)
Than means the variable is substituted to it's value in first review of the comand by the shell and second time the shell does not process the file name substitution which is required to evaluate (maybe, better to say: expand) the @(test|test).
To correct that the 'eval' command works:
Code:
> ls @(test|test1)/test.txt
test1/test.txt  test/test.txt
> cat @(test|test1)/test.txt
another test file in test1 dir <<<
proba
> var=test\|test1
> echo $var
test|test1
> eval cat @($var)/test.txt
another test file in test1 dir <<<
proba

# 3  
Old 03-26-2008
Perfect, works like a champ. Thanks for the quick reply.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to delete all lines before a particular pattern when the pattern is defined in a variable?

I have a file Line 1 a Line 22 Line 33 Line 1 b Line 22 Line 1 c Line 4 Line 5 I want to delete all lines before last occurrence of a line which contains something which is defined in a variable. Say a variable var contains 'Line 1', then I need the following in the output. ... (21 Replies)
Discussion started by: Soham
21 Replies

2. UNIX for Dummies Questions & Answers

How to import a variable Used in Another Korn Shell Script?

Hi I am using two shell scripts which are running on the system simultaneously. And in one of the script i am exporting an Integer Variable. Now i want to use the variable in another script. But i cannot run the first script in the second as the first script has many other functions which... (3 Replies)
Discussion started by: Ajesh
3 Replies

3. Shell Programming and Scripting

Pattern match exclusive return pattern/variable

I have an application(Minecraft Server) that generates a logfile live. Using Crontab and screen I send a 'list' command every minute. Sample Log view: 2013-06-07 19:14:37 <Willrocksyea1> hello* 2013-06-07 19:14:41 <Gromden29> hey 2013-06-07 19:14:42 Gromden29 lost connection:... (1 Reply)
Discussion started by: gatekeeper258
1 Replies

4. Shell Programming and Scripting

Korn Shell regular pattern

Hello, I can't seem to understand korn shell regular expression. I am trying to extract the tagfrom its own filename string. var="LNX_1.2.0.0.af329a3da.tar" whereby af329a3da is the tagI am trying to extract out from. I am trying to avoid using IFS because future modifications... (5 Replies)
Discussion started by: howhan
5 Replies

5. Shell Programming and Scripting

Korn Shell for pattern matching and extracting

Guys, i'm new to shell scripting. Here's what i need. I need a shell script which would read a file containing only 1 line which never changes. File containts - SQL_Mgd_Svc_ELONMCL54496 |EMEA\brookkev, EMEA\fieldgra, EMEA\tidmamar, EMEA\attfiste, EMEA\baldogar, EMEA\clarkia2, EMEA\conwasha,... (9 Replies)
Discussion started by: butterfly20
9 Replies

6. Programming

How to refer to variable (korn shell)?

Hi I have the following block of code in korn shell and don't now how to refer to variable `print variable1.$dvd` ? --- integer dvd=4 integer number=0 while (( dvd!=0 )) do print "Iteracja numer : $dvd" print "$_" #it refers to $dvd var but want to refer... (3 Replies)
Discussion started by: presul
3 Replies

7. Shell Programming and Scripting

Pattern manipulation in korn shell script using sed.

Hi, Could any one let me know, how can I cut the last field in below mentioned line. net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.37.0,10.253.0.1 net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.1.0,10.253.0.1 net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.38.0,10.253.0.1... (3 Replies)
Discussion started by: ajilesh
3 Replies

8. Shell Programming and Scripting

compound variable in korn shell

in a text " Korn Shell Unix programming Manual 3° Edition" i have found this sintax to declare a compoud variable: variable=( fild1 fild1 ) but this sintax in ksh and sh (HP-UNIX) not work... why?? exist another solution for this type of variable ??? (5 Replies)
Discussion started by: ZINGARO
5 Replies

9. Shell Programming and Scripting

compound variable in korn shell

in a text " Korn Shell Unix programming Manual 3° Edition" i have found this sintax to declare a compoud variable: variable=( fild1 (0 Replies)
Discussion started by: ZINGARO
0 Replies

10. UNIX for Dummies Questions & Answers

does this variable call work--Korn

I am new to the UNIX environment, but not to programming. My intention is to create a 2D array and print it. Since the Korn Shell does not support that kind of variable, the following is my solution right now. I have created a group of variables as follows: table00 table01 table02 table10... (2 Replies)
Discussion started by: morkfard
2 Replies
Login or Register to Ask a Question