|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | 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 | Display Modes |
|
#1
|
|||
|
|||
|
Escaping ** correctly
Hello This should be easy, but bash is giving me headaches. At the command line the following command works: Code:
duplicity --include /home --exclude '**' / file:///foo Doing that from a script is not straightforward. Note that it is basically a requirement that I place the includes and excludes into variables. These alternatives do not work, as none of them produces the above output: Code:
args="--include /home --exclude '**'" duplicity $args src tgt args='--include /home --exclude **' duplicity $args src tgt args="--include /home --exclude \*\*" duplicity $args src tgt args="--include /home --exclude **" duplicity "$args" src tgt So what is the magic incantation, please? Last edited by zaxxon; 02-12-2010 at 10:45 AM.. Reason: use code tags please, ty |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
The problem is that you can't put quoted strings inside variables and expect them to get split sanely AFTER substitution has already happened. It'll split apart on spaces but not much else. It doesn't re-check for quoted strings etc. after substitution's already happened. So your script isn't being given **, it's being given '**', quotes and all! And yet, if you remove the quotes, it WILL substitute for *, even though it doesn't substitute for strings... Put them in an array so there's no guessing at all involved in which parts are string, which parts are quotes, and where it should split them apart; it'll do so just like you'd expect of program arguments. There's a magic syntax to spit out an entire array as properly separated parameters too. Code:
ARGS=( --include /home --exclude "**" )
# This array syntax spits out an array, splitting ONLY between elements.
program "${ARGS[@]}"This won't work in ordinary sh, which doesn't have arrays. Last edited by Corona688; 02-12-2010 at 11:20 AM.. |
| The Following User Says Thank You to Corona688 For This Useful Post: | ||
brsett (05-27-2010) | ||
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Hello,
you can use --exclude-regexp if you dont have any files starting with a dot in the current directory. so the glob would not be expanded args="--include /home --exclude-regexp '.*'" One question: why do you need to have --exclude? Is duplicity recursive in nature.? anyways I hope that solves your problem. Regards, Gaurav. |
|
#4
|
|||
|
|||
|
Quote:
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Escaping backslash | swmk | UNIX for Dummies Questions & Answers | 9 | 10-07-2008 12:57 PM |
| Escaping the * character in ksh. | arvindcgi | Shell Programming and Scripting | 6 | 05-19-2008 09:50 AM |
| incorrect quotes/escaping? | new2ss | Shell Programming and Scripting | 2 | 09-02-2007 10:39 PM |
| Escaping '*' in Bash | rkshukla14 | Shell Programming and Scripting | 7 | 04-04-2007 11:45 PM |
| escaping * in korn shell | prekida | Shell Programming and Scripting | 3 | 07-13-2005 05:19 PM |
|
|