【发布时间】:2013-12-09 19:24:11
【问题描述】:
以下脚本正在只有 csh 的 HP-UX 机器上运行。
#!/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
目前没有检索到所有需要的值。
这是输入的信息:
Sample
1.-PL000000002002124215 12 DAY 3/11/2013
2.-PL000000002002365287 67 DAY 22/11/2013
3 PL000000002002745214 35 DAY 27/11/2013
根据电子邮件中的信息,第一行是唯一存储到变量中的内容。
预期输出是:
PL000000002002124215
PL000000002002365287
PL000000002002745214
感谢@keith-thompson 和@shellter 的回复!
这是基于您的信息和我所做的更改的输出:
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
【问题讨论】:
-
"只有 csh"?如果它没有至少
/bin/sh,我会感到惊讶,Bourne shell,通常被认为更适合脚本编写。 -
请考虑编辑您的问题以包含您当前的输出。从您的主题行中,我猜您只会回显输入的第一行。是的?通过
set input = $<分配数据,对于多行输入可能根本不起作用,或者几乎肯定需要您在每行输入的末尾使用 `\` 字符转义换行符。祝你好运!