]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
avoid infinite recursion
authormkrzewic <mikolaj.krzewicki@cern.ch>
Tue, 9 Dec 2014 15:42:18 +0000 (16:42 +0100)
committermkrzewic <mikolaj.krzewicki@cern.ch>
Tue, 9 Dec 2014 15:42:52 +0000 (16:42 +0100)
PWGPP/scripts/utilities.sh

index 35d519d128c1eff5201784858683c9837983044b..60ee33d9423d8762724236bb58f0df1f22554753 100755 (executable)
@@ -169,14 +169,28 @@ setYear()
   #set the year
   #  ${1} - year to be set
   #  ${2} - where to set the year
-  local year1=$(guessYear ${1})
-  local year2=$(guessYear ${2})
+  local year1=$(guessYearFast ${1})
+  local year2=$(guessYearFast ${2})
   local path=${2}
   [[ ${year1} -ne ${year2} && -n ${year2} && -n ${year1} ]] && path=${2/\/${year2}\//\/${year1}\/}
   echo ${path}
   return 0
 }
 
+guessYearFast()
+{
+  #guess the year from the path, pick the rightmost one
+  local IFS="/"
+  declare -a pathArray=( ${1} )
+  local field
+  local year
+  for field in ${pathArray[@]}; do
+    [[ ${field} =~ ^20[0-9][0-9]$ ]] && year=${field}
+  done
+  echo ${year}
+  return 0
+}
+
 run2year()
 {
   #for a given run print the year.