1

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

1 Answer 1

2

This line is the problem:

fdate=` $fname | cut -c2-4 `

It should be:

fdate=`echo "$fname" | cut -c2-4`
Sign up to request clarification or add additional context in comments.

2 Comments

My poor. Thanks... All set :-) Had been stuck on this for like last 40 minutes. Huh...
Could you please help me in this too. Link => stackoverflow.com/questions/27900170/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.