« first day (4924 days earlier)      last day (185 days later) » 

4:34 PM
@ilkkachu why are you setting IFS twice? Is that an oversight or some clever trick for an edge case I can't think of?
3
A: Issue expanding variable with multiple wildcards in bash shell script with mv / rename

ilkkachuMostly to focus on why you get no effect and no errors, this: perlExp=\'s/^/\\/home\\/test\\/alpha\\/"$fldr"\\//\' rename --verbose "$perlExp" ${fullmatchStr} assigns to perlExp and passes to perl the string 's/^/\/home\/test\/alpha\/...\//' with the single quotes. That's a valid Perl expression...

#!/bin/bash
IFS=
while IFS=" " read -r fldr matchStr
do
    perlExp='s#^#/tmp/test/alpha/'"$fldr"'/#'
    fullmatchStr="testfile - $matchStr - *.txt"
    rename --verbose "$perlExp" ${fullmatchStr}
done < test.dat
The first one would apply to all the commands within the loop and the second one would only apply to the read, no?
yes, exactly, the IFS=" " read was in the original post. It does look odd the way I wrote it though..
Putting the IFS= inside the loop might make it seem like it only applies within the loop body. It'll probably look awkward or confusing either way, sigh.
IFS= rename --verbose "$perlExp" ${fullmatchStr}
maybe?
no, that's exactly what doesn't work. :) (IFS= ; rename ...) might, but it's a useless subshell
4:49 PM
UUOSS
But why bother setting it (well, blanking it) outside the loop at all, @ilkkachu?
I don't think it makes sense in the loop either, not unless the OP has tabs in the file that should not be taken as separators which seems unlikely, but if you're setting in the loop, why set it to the empty string outside it?
5:05 PM
@terdon The unquoted expansion of ${fullmatchStr} needs to have IFS set to the empty string beforehand to prevent word splitting there. But then read needs to have it set to something that contains the space to get the two separate fields from the file. Conflicting demands. And then read would inherit the global IFS, if it wasn't explicitly given another value...
Doing while one; do two; IFS=; three; done; four would make it look like it's blanked only for three, while it really would be blanked for everything but the first repeats of one and two, so in that sense it makes it IMO clearer to set it before the loop.
...so muru's solution of just not putting the glob in a variable in the first place is better, too
@ilkkachu AH! Yes, of course! I hadn't thought to use IFS and so couldn't get the damned thing to work. That makes sense, thanks.
Insofar as anything to do with IFS and word splitting makes sense
heh yeah, sorry, I meant makes "sense"
now my head hurts and I was the one who wrote that answer, asdf
There must be a better way than what the OP is doing. Maybe reading the dest and glob file into a shell array first, and then do for file in testfilename*$glob*txt; do... or something
5:18 PM
switching to Perl completely so they can call split() and glob() explicitly when they want to comes to mind...

« first day (4924 days earlier)      last day (185 days later) »