1

I am reviewing a shell script and found this lines :

DIR=/home/bot/REP_INV/
LIST=/root/ListeTRI.txt
...
ligne=`cat $LIST`
for i in $ligne
do
    /bin/cp  $DIR*$i* /root/$i/InvExt/
    /bin/cp  $DIR*${i,,}* /root/$i/InvExt/
done

In the DIR folder I have a large number of file and in the LIST file I have code to sort those files. The goal is to sort the files into other folders.

I understand that the first copy command should copy files from DIR to the right folder in /root/ depending on the name of the file (it should have the code from the LIST in its name)

But I have no clue for the purpose of this second copy command. Does anyone know that syntax ${i,,} in /bin/cp $DIR*${i,,}* /root/$i/InvExt/ ?

1 Answer 1

2

From Bash Reference Manual:

${parameter^pattern}
${parameter^^pattern}
${parameter,pattern}
${parameter,,pattern}

This expansion modifies the case of alphabetic characters in parameter. The pattern is expanded to produce a pattern just as in filename expansion. Each character in the expanded value of parameter is tested against pattern, and, if it matches the pattern, its case is converted. The pattern should not attempt to match more than one character. The ^ operator converts lowercase letters matching pattern to uppercase; the , operator converts matching uppercase letters to lowercase. The ^^ and ,, expansions convert each matched character in the expanded value; the ^ and , expansions match and convert only the first character in the expanded value. If pattern is omitted, it is treated like a ?, which matches every character.

So ${i,,} expands to the value of i but all uppercase characters are converted to lowercase. Example:

$ i=CaMeL
$ echo "$i"
CaMeL
$ echo "${i,,}"
camel
$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .