Something weird happening here, or I couldn't figure out myself.
I am unable to assign value from one variable to other. What I am doing is, retrieving filename and then substring it to check the last 6 letters which is the creation date(yymmdd) of that file, needed for further processing. I have listed 2 different debugging version, which is retriving the filename, but some problem is happening during substring and assigning it to another variable.
- Although during basename itself, it's doing perfect with substring (go to Debugging Version 2)
Debugging version 1:
Code:
fname=''
fdate=''
for file in /home/fimsctl/datafiles/outbound/timelog/timelog_file_*.csv ; do
echo "Debugging Test: 123"
fname=` basename $file `
echo "Debugging Test: 456"
echo "$fname"
echo "Debugging Test: 789"
fdate=` $fname | cut -c2-4 `
echo "Debugging Test: abc"
echo "$fdate"
echo "Debugging Test: def"
done
Output:
Debugging Test: 123
Debugging Test: 456
timelog_file_150112.csv
Debugging Test: 789
testb.ksh[119]: timelog_file_150112.csv: not found
Debugging Test: abc
Debugging Test: def
Debugging version 2:
Code:
fname=''
fdate=''
for file in /home/fimsctl/datafiles/outbound/timelog/timelog_file_*.csv ; do
echo "Debugging Test: 123"
fname=` ( basename $file ) | cut -c14-19 `
echo "Debugging Test: 456"
echo "$fname"
echo "Debugging Test: 789"
fdate=` $fname | cut -c2-4 `
echo "Debugging Test: abc"
echo "$fdate"
echo "Debugging Test: def"
done
Output:
Debugging Test: 123
Debugging Test: 456
150112
Debugging Test: 789
testb.ksh[119]: 150112: not found
Debugging Test: abc
Debugging Test: def