What is the bug in the following script?
#! /bin/tcsh -f
cut -d" " -f2 ${1} | ./rankHelper
Script rankHelper:
#! /bin/tcsh -f
set line = ($<)
while(${#line} != 0)
cat $line
set line = ($<)
end
File lines from which the data was sent:
053-3787837 038280083
052-3436363 012345678
053-3232287 038280083
054-3923898 033333333
052-2222333 012345678
052-1111111 012390387
I run it using:
> ./rank lines
Why do I receive only the following one number?
038280083
I thought cut must cut two fields from all rows. I expect to see the second field from all rows from the lines:
dos2unix: converting file rank to UNIX format ...
> ./rank lines
>
> cat -A rank
#! /bin/tcsh -f$
cut -d" " -f2 ${1} | ./rankHelper
> cat -A rankHelper
#! /bin/tcsh -f$
set line = ($<)$
$
$
while(${#line} != 0)$
$
echo $line$
set line = ($<)$
end
I’m working on C shell.
I changed
rankto this:and ran
and it worked for me.
Edit: If you still want to use
rankHelperfor some reason (homework?), try changing, inrankHelperthe commandto