sh script to csh script

sh script to csh script

Post by Ed Taal » Sat, 07 Apr 2001 02:39:15



hello all,

#!/bin/sh
#B
while read line
do
  program $line
end

The input looks like this
--------
-I 1114 -S 010331 -E 010401
-I 1115 -S 010330 -E 010402
--------
It works just fine. What I want to do is to get this working under csh.
The following does not work.

#!/bin/csh -f
#
while (`read line`)
  program $line
end

Please help!

Ed

 
 
 

sh script to csh script

Post by Bill Marcu » Sat, 07 Apr 2001 04:08:38



>It works just fine. What I want to do is to get this working under csh.
>The following does not work.

>#!/bin/csh -f
>#
>while (`read line`)
>  program $line
>end

The csh equivalent of "read line" is
set line="$<"
but you should be able to use sh scripts even if your login shell is csh.

 
 
 

sh script to csh script

Post by m.bannis.. » Wed, 11 Apr 2001 00:25:13


Your csh while loop doesn't work because the read command is not a csh
built-in command, so it runs sh which sets the line variable inside the sh
child shell, which is lost when the child exits.

Here is the best alternative I can think of, works fine as long as none of
your input lines are expected to be blank...

#!/bin/csh
while (1)
        set line="$<"
        if ( "$line" == "" ) break
        program $line
end

Alternatively, the shorter approach is to use nawk or gawk (awk doesn't have
the system function available to it)...

#!/bin/csh
nawk '{system("program "$0)}'

Have fun,
Mark.



>hello all,

>#!/bin/sh
>#B
>while read line
>do
>  program $line
>end

>The input looks like this
>--------
>-I 1114 -S 010331 -E 010401
>-I 1115 -S 010330 -E 010402
>--------
>It works just fine. What I want to do is to get this working under csh.
>The following does not work.

>#!/bin/csh -f
>#
>while (`read line`)
>  program $line
>end

>Please help!

>Ed

 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts