Quote:
Originally Posted by jim_geek
the program is
for ((i=0;i < 5;i++))
do
j=$j;
while [ $j -ne 0 ]
do
echo $j \n;
j=$(($j-1));
done
done
|
But that isn't the program you used to generate the output you quoted, because it wouldn't generate that output.
You should have done a copy/paste to post the exact program you tested.
In the above, you have
j=$j;
The correct program (and your tested program) must have
j=$i;
In the above, you have
echo $j \n;
but that is neither correct nor what you tested.
You need to suppress the newline, which is done with
echo -n $j
But then you need to add another newline once per outer loop by adding another instruction somewhere.
Quote:
the logic of program is correct
|
Your program is wrong. I don't know what you think you mean by its "logic" is correct.
Your title "New Line Char Is not working properly in linux" and your claim that "the logic of program is correct" both indicate you prefer to blame the tool rather than look for your mistake. You'll find that attitude is not very effective when asking for help and even less effective when trying to learn enough that you won't need to ask for help.
BTW, I don't know shell scripting myself. For example, I don't know the significance of the ; on some of your lines. Those seem to make no difference if I test your script with/without them in bash. Of course, I also can't tell whether you are using bash. So in answering your post, I didn't use any scripting knowledge, just basic programming logic (independent of language) plus a quick glance at the output from something you should also look at:
Possibly someone who actually knows shell scripting will have something constructive to add. I answered because no one else had answered and because the error was obvious enough to answer without shell scripting knowledge.