Frontier Software

Transforming

Lowercasing

${varname@L}

#!/bin/bash

# find_schema 'artists' 'Arno Carstens'
# Returns just the first match
function find_schema {
  local path
  local file
  path="${2@L}"
  path="*${path//[^[:alnum:]]/\*}*"
  path="/usr/local/webapps2/*/content/${1}/${path}/schema.json"
  for file in $path; do
    if [[ -f $file ]]; then
      echo "$file"
      return 0
    fi
  done
}

ExampleGroup 'list artist and venue schema.json files'

  Example 'Find schema.json for "Arno Carstens"'
    When call find_schema 'artists' 'Arno Carstens'
    The output should eq "/usr/local/webapps2/joeblog/content/artists/arno-carstens/schema.json"
  End

  Example 'Find schema.json for "No File Created"'
    When call find_schema 'artists' 'No File Created'
    The output should eq ''
  End

  Example 'Find schema.json for "Black Cat Bones"'
    When call find_schema 'artists' 'Black Cat Bones'
    The output should eq '/usr/local/webapps2/joeblog/content/artists/blackcatbones/schema.json'
  End

Example 'Find schema.json for "Bailey`s"'
    When call find_schema 'venues' "Bailey's"
    The output should eq '/usr/local/webapps2/joeblog/content/venues/baileys/schema.json'
  End
  

End
ExampleGroup 'from https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html'
# also https://opensource.com/article/17/6/bash-parameter-expansion

# https://stackoverflow.com/questions/40732193/bash-how-to-use-operator-parameter-expansion-parameteroperator
  Example '${parameter@operator} U'
    foo="bar"
    When call echo "${foo@U}"
    The output should eq "BAR"
  End

  Example '${parameter@operator} u'
    foo="bar"
    When call echo "${foo@u}"
    The output should eq "Bar"
  End

  Example '${parameter@operator} L'
    foo="BAR"
    When call echo "${foo@L}"
    The output should eq "bar"
  End

  Example 'associative array JSON path'
    foo=""performer",0,"sameAs",0"
    When call echo "${foo}"
    The output should eq "performer,0,sameAs,0"
  End

  # Output to be reused as input of another command
  Example '${parameter@operator} Q'
    foo=""performer",0,"sameAs",0"
    When call echo "${foo@Q}"
    The output should eq "'performer,0,sameAs,0'"
  End

  Example '${parameter@operator} a'
    declare -A arr=(["foo"]="bar")
    When call echo "${arr@a}"
    The output should eq "A"
  End

  Example '${parameter@operator} K'
    declare -A arr=([""performer",0,"sameAs",0"]="bar")
    When call echo "${arr[@]@K}"
    The output should eq "performer,0,sameAs,0 \"bar\" "
  End

  Example '${parameter@operator} k'
    declare -A arr=([""performer",0,"sameAs",0"]="bar")
    When call echo "${arr[@]@k}"
    The output should eq "performer,0,sameAs,0 bar"
  End

End