#!/bin/ksh
for file in "file1.txt" "file2.txt" "file3.txt" "file4.txt"
do
L="$(tail -1 $file)"
NUM=${L%%|*}
DAT=${L##*|}
echo $NUM
echo $DAT
done
Now here,suppose for file1.txt
L will have data like 56|06-07-2010
So, it should be
NUM as 56 & DAT as 06-07-2010
but through the script NUM is getting NULL value and DAT is having 56|06-07-2010 although when am running it without script all works fine...Please tel wher am i wrong.....
I don't know, perhaps you are not using the exact same ksh as you are using in your script?
In this case whether | should be escaped in variable expansion is at least a grey area and probably is open to interpretation. In this case I would just escape it - even if it is not required - just to avoid problems. This should work in any Posix shell.