I have some tables, in which I need to replace several values. I have different commands sed and tr that work just fine when I apply them to a single file.But somehow, when I want to build a loop from this commands it is not working at all. Here is my loop:#!/bin/bashin_dir=/home/stevens/SUMARIO/regional_model/data/basinstations=almourol alton cuntan eldeim farakka koulikoro lobith louth olivenca stolb tangnaihaigcms=gfdl-esm2m hadgem2-es ipsl-cm5a-lr miroc-esm-chem noresm1-mscenarios=rcp8p5for station in ${stations};do  echo go to directory  cd ${in_dir}/${station}  for gcm in ${gcms};do    for rcp in ${rcps};do      cd ${in_dir}/${station}      echo replace datum      sed 's/datum/YEAR-MONTH-DAY/g' ${station}_${gcm}_${scenario} > ${station}_${gcm}_${scenario}.c      echo delete hour      sed 's/ 12:00:00//g' ${station}_${gcm}_${scenario}.c > ${station}_${gcm}_${scenario}.cs      echo replace - to ;      tr - ; < ${station}_${gcm}_${scenario}.cs > ${station}_${gcm}_${scenario}.csv      rm ${station}_${gcm}_${scenario}.cs ${station}_${gcm}_${scenario}.c    done  donedoneDoes anyone has an idea why this loop doesnt work.
reformat values in a table
sed;tr;table
you haven't defined the rcps variableyou defined scenarios but used scenarioHere's a version of your script that fixes those problems and makes a few other improvements:formatted with extra newlines and aligned indentation to improve readabilityuse arrays rather than space-separated stringsuse sed once rather than multiple times plus trdouble-quotes all the variablessingle-quotes all fixed stringsdefines a variable ($fname) to hold the constructed filename (${station}_${gcm}_${scenario}) rather than re-constructing it every time you use it, which is both much harder to read AND very prone to typing errors.#!/bin/bashin_dir='/home/stevens/SUMARIO/regional_model/data/basin'stations=(almourol alton cuntan eldeim farakka koulikoro lobith louth          olivenca stolb tangnaihai)gcms=(gfdl-esm2m hadgem2-es ipsl-cm5a-lr miroc-esm-chem noresm1-m)scenario='rcp8p5'rcps=(a b c)for station in ${stations[@]} ; do  cd ${in_dir}/${station}  for gcm in ${gcms[@]}; do    for rcp in ${rcps[@]} ; do      fname=${station}_${gcm}_${scenario}      echo replace datum: $fname      sed -e 's/datum/YEAR-MONTH-DAY/g;              s/ 12:00:00//g;              s/-/;/g' $fname > ${fname}.csv    done  donedoneIf you want to replace the string datum with an actual date, you'd have to do something like:define YMD=$(date +%Y-%m-%d) along with the other vars and arraysand rewrite the sed script as this:      sed -e 's/datum/'${YMD}'/g;              s/ 12:00:00//g;              s/-/;/g' $fname > ${fname}.csvBTW, if you really did mean to have multiple scenarios, you'll have to define scenarios as another array and add another loop for scenario in ${scenarios[@]} ; do ..... done