[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] [BASH] parameter expansion



Kristian Nørgaard <sslug@sslug> writes:

> sslug@sslug echo $EXCL
> --exclude '*~'

Man skal holde tungen lidt lige i munden. Målet er at tar(1) skal se
de to argumenter [--exclude] og [*~]. Det her viser at tar(1) kommer
til at se to argumenter [--exclude] og ['*~'] og ganske rigtigt
ekskluderer tar(1) alle filer hvis navn begynder med en apostrof og
slutter med tilde-apostrof.

Problemet er at hvis $EXCL indeholder en ', så vil bash prøve at
escape den hvorefter den fortolker hele strengen. Det vil sige at du
sætter nogle plinger, bash beskytter dem hvorefter bash fortolker
resultatet (fjerner det yderste lag beskyttelse). Løsningen er
tilsyneladende at indføre et ekstra lag fortolkning:

$ ls
foobar  foobar~  foobaz  plugh  printargs  xyzzy  xyzzy~
$ cat ./printargs
#!/usr/bin/perl
for (@ARGV) {
  print "[$_]\n";
}
$ EXCL="--exclude '*~'"
$ ./printargs $EXCL
[--exclude]
['*~']
$ eval ./printargs $EXCL
[--exclude]
[*~]
$

Det vil sige at du bør bruge en eval før din tar.

-- 
 http://peter.makholm.net/ |   First you fall in love with Antarctica, and
     sslug@sslug     |                     then it breaks your heart
                           |                                 -- Antarctica


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-08-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *