Reputation
2,083
Top tag
Next privilege 2,500 Rep.
Create tag synonyms
Badges
3 19 33
Impact
~100k people reached

Mar
6
comment On passing arguments to programs through array variables
Yes, thank you, I see that. I can rationalize these things after-the-fact (i.e. when I know where to focus), but to sort out all of the possible ins and outs ahead of time is, for me, the equivalent of multiplying two 5-digit numbers in my head; it's beyond what I can do easily. In no other programming context do I have such difficulties. For me shell quoting is pure hell.
Mar
6
comment On passing arguments to programs through array variables
Even though I've been using zsh for years (decades even), I have never managed to fully understand quoting... Setting EXCLUDES=( --exclude='/foo' --exclude='/bar' --exclude='/baz' ) causes no problem, despite the single quotes. But, as you point out, using EXCLUDES+=( "--exclude='$item'" ) does lead to problems. I realize that it all has to do with the relative timing of the various expansions and whatnot that happen during zsh's parsing. This is what I cannot keep track of, and is at the root of 90% of my problems with zsh.
Mar
6
accepted On passing arguments to programs through array variables
Mar
6
revised On passing arguments to programs through array variables
added 4 characters in body
Mar
6
asked On passing arguments to programs through array variables
Mar
6
accepted Possible redirection bug in zsh 5x
Mar
5
revised Possible redirection bug in zsh 5x
added 252 characters in body
Mar
5
revised Possible redirection bug in zsh 5x
added 116 characters in body
Mar
5
asked Possible redirection bug in zsh 5x
Mar
2
comment How to split a string on a control character?
@cuonglm: thanks for the info; it's too bad this sort of information is not in the documentation (in the case of my shell's version that would mean an explicit mention that separators in variables are not supported)... Then again, the business with the p flag is in the documentation, and I still managed to miss it. :/
Mar
2
comment How to split a string on a control character?
@cuonglm: oh well, I guess it's time for me to upgrade, because that's the sort of thing that should work. :)
Mar
2
comment How to split a string on a control character?
Sorry, those were typos when I wrote the comment; I added an EDIT to my post where I show exactly the code that I tried, along with the generated output. Again, sorry for the confusion.
Mar
2
revised How to split a string on a control character?
added 412 characters in body
Mar
2
comment How to split a string on a control character?
Hmmm... I tried something like that, in fact, when I first saw your answer, but for some reason it did not work. More specifically, I had tried SPLIT=(${(s:$DELIM:)FOO}), but $SPLIT ended up with only one element (equal to the original $FOO). In contrast, with the version where the delimiter is hard-coded, namely, SPLIT=(${(s:\034:)FOO}), $SPLIT is an array of several elements, as desired...
Mar
2
comment How to split a string on a control character?
Thanks! After I posted my question it occurred to me that I could stick the separator inside a variable, say DELIM, and do something with eval ... \${(s:$DELIM:)FOO}. This is definitely much uglier than your solution, but being able to avoid hard-coding the delimiter everywhere has its merits.
Mar
2
accepted How to split a string on a control character?
Mar
2
asked How to split a string on a control character?
Feb
22
asked rsync's “Read-only file system (30)” error
Feb
22
comment How can I find out if a relative symlink is internal to a certain subtree or not?
Thanks! I see what you mean! Not a pleasant sight at all. Shell programming must be the hardest type of programming I know of...
Feb
22
comment How can I find out if a relative symlink is internal to a certain subtree or not?
I found studying this post very instructive. May I ask you a couple of questions? Is there any significance in the fact that in needle=${needle%??} haystack=${haystack%??} the needle variable is dealt with first, whereas in the next line it is the other way around? Also, how come your return statements don't explicitly return a non-zero value (to indicate error)? Last one: would it make sense to factor out the entire transformation (the call to readlink, plus the two suffix truncations) to a separate _canonicalize_path helper function?