Can any one please tell me where the error in below script. Output is not as per my requirement. if condition not comparing the result of record count of a file with 1. where is the pbm in my script? Appreciate your help..
#!/bin/ksh
#Module-
#Summary- To move the file to direcotries if condition satisified or failed
#Author-
set -x
Dir1="/home/s117013"
Dir2="/home/s117013/data"
Dir3="/home/s117013/tmp"
cd $Dir1
filename=test_3.sh
i=`gawk '{print $NR}' test_3.sh | wc -l`
if ($i > 1);
then
cp $Dir1/$filename $Dir3/$filename`date +%Y%m%d%H%M%S`.csv
else
cp $Dir1/$filename $Dir2/$filename_`date +%Y%m%d%H%M%S`.csv
fi
output:
+ sh test_print.sh
+ Dir1=/home/s117013
+ Dir2=/home/s117013/data
+ Dir3=/home/s117013/tmp
+ cd /home/s117013
+ filename=test_3.sh
++ gawk '{print $NR}' test_3.sh
++ wc -l
+ i=21
+ 21
test_print.sh: line 12: 21: command not found
++ date +%Y%m%d%H%M%S
+ cp /home/s117013/test_3.sh /home/s117013/data/20140212130431.csv
Both ((expression)) and $((expression)) perform an arithmetic evaluation of expression. After evaluating expression, $((expression)) returns a string representing the resulting value. ((expression)) returns a 0 exit status if expression evaluates to a non-zero value and 1 otherwise.
Other than the time taken to format the results, there shouldn't be any noticeable difference in speed between ((expression)) and $((expression)) .
Note that the standards require conforming shells to support arithmetic expansion ( $((expression)) ). The standards explicitly allow for the arithmetic evaluation command ( ((expression)) ) to be provided, but do not currently require conforming shells to provide it. The standards also explicitly require applications that invoke nested subshells to separate the opening parentheses opening the subshell environments with one or more IFS characters to avoid an ambiguity in the grammar in shells that support the arithmetic evaluation command.
And that is dependent on the code being in a loop. ksh precompiles loops and executes the compiled code. With the second form, ksh must expand the variable and then rescan the full resulting expression. With the first form ksh can use the compiled code with no rescan.