0

The following script is being run on a HP-UX box that has only csh.

#!/bin/csh -fx
set todaysDate = `date +%m%d%y-%H:%M` 
echo -n Paste the email information here: 
set input = $<
set info = `echo $input > jcc.$todaysDate`
sed 's/.*\(PL[0-9]*\).*/\1/' jcc.$todaysDate > sample2
echo $info
echo -n Type y if the output is correct or n if it is incorrect
set answer = $<
if($answer == y || $answer == Y) then
#send to other script
else if($Answer == n || $Answer == N) then
exit
else
echo "Invalid input"
endif

It is currently not retrieving all the values needed.

Here is the information being typed:

Sample
1.-PL000000002002124215                               12                     DAY 3/11/2013
2.-PL000000002002365287                              67                     DAY 22/11/2013
3  PL000000002002745214                               35                     DAY 27/11/2013

Based on the information from the email, The first line is the only thing that it is getting stored into the variable.

Expected output is:

PL000000002002124215
PL000000002002365287
PL000000002002745214

Thank you for the replies @keith-thompson and @shellter !

This is the output based on your information and changes I did:

set todaysDate = `date +%m%d%y-%H:%M`
date +%m%d%y-%H:%M
echo -n Paste the email information here:
Paste the email information here:Sample
1.-PL000000002002124215                               12                     DAY 3/11/2013
set input = Sample
2.-PL000000002002365287                              67                     DAY  22/11/2013
echo Sample
3  PL000000002002745214                               35                     DAY  27/11/2013sed s/.*\(PL[0-9]*\).*/\1/ jcc.120913-15:10
echo Sample
Sample
echo -n Type y if the output is correct or n if it is incorrect
Type y if the output is correct or n if it is incorrectset answer = 1.- PL000000002002124215                               12                     DAY 3/11/2013
if ( 1.-PL000000002002124215 12 DAY 3/11/2013 == y || 1.-PL000000002002124215 12 DAY   3/11/2013 == Y ) then
if: Badly formed number.
homes/ 32% 2.-PL000000002002365287                               67                     DAY 22/11/2013
2.-PL000000002002365287: Command not found.
homes/ 33% 3  PL000000002002745214                                35                     DAY 27/11/2013
sayayinx
  • 21
  • 4
  • "that only has csh"? I'd be astonished if it didn't have at least `/bin/sh`, the Bourne shell, which is generally considered better for scripting. – Keith Thompson Dec 09 '13 at 20:07
  • please consider editing your question to include your current output. From your subject line I'm guessing that you're only getting the first line of your input echoed back. yes? Assigning data via `set input = $<`, may not work at all with multiline input OR will almost definitely require that you escape the line-feeds with `\\` chars at the end of each line of input. Good luck! – shellter Dec 09 '13 at 20:30

1 Answers1

0
set info = `echo $input > jcc.$todaysDate`

This sets $info to the output of the command echo $input > jcc.$todaysDate. Since its output is redirected to a file, there is no remaining out to store in $info.

There's no need to capture the output of that echo command anyway, since you already have it in $input.

I haven't analyzed your entire script, but for starters I'd replace the above by just:

echo $input > jcc.$todaysDate`

and replace any references to $info by $input.

And I strongly suggest indenting your code; it makes it a lot easier to read and maintain.

Finally, you should read Csh Programming Considered Harmful. You say your system only has csh, but I'm sure it has some version of the Bourne shell installed as /bin/sh.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631