0

I try to contribute to a Wikimedia opensource project but I don't get what ##*/ means in bash ${qidpath##*/}. Searching on google for ##*/ is chaotic.

/tmp/datasets/raw/* contains a list of folders.

    for qidpath in  /tmp/datasets/raw/*;
    do
      qid=$(echo ${qidpath##*/} | cut -d'-' -f 1)
      if [[ $qid == Q* ]] ; then
        echo "--> Processing ${qid}..."
        /usr/bin/python3.5 /home/www/CommonsDownloadTool/commons_download_tool.py --keep --sparqlurl https://lingualibre.org/bigdata/namespace/wdq/sparql --sparql "SELECT ?file ?filename WHERE { ${query} ?record prop:P4 entity:${qid}. }" --threads 4 --directory  /tmp/datasets/raw/ --output "/tmp/datasets/${qidpath##*/}.zip" --fileformat ogg
      fi
    done
Cyrus
  • 84,225
  • 14
  • 89
  • 153
Hugolpz
  • 17,296
  • 26
  • 100
  • 187

1 Answers1

1

This will remove all pattern beginning by */: this will get a filename in your case.

Add the manual to your bookmark:

${parameter#word}

${parameter##word}

The word is expanded to produce a pattern and matched according to the rules described below (see Pattern Matching). If the pattern matches the beginning of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the ‘#’ case) or the longest matching pattern (the ‘##’ case) deleted. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.

NoDataFound
  • 11,381
  • 33
  • 59