2013-12-09 40 views
0

以下腳本正在僅具有csh的HP-UX盒上運行。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 

它目前沒有檢索到所有需要的值。

這裏是正在鍵入的信息:

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 

謝謝你的回覆@基思 - 湯普森和@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 
+0

「只有csh」?如果它至少沒有'/ bin/sh',Bourne shell,它通常被認爲對腳本更好,我會感到驚訝。 –

+0

請考慮編輯您的問題以包含您當前的輸出。從你的主題來看,我猜你只會讓你輸入的第一行回顯。是?通過'set input = $ <'分配數據可能根本無法使用多行輸入OR幾乎肯定會要求您在每行輸入的末尾用'\\'字符替換換行符。祝你好運! – shellter

回答

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

這臺$info到命令echo $input > jcc.$todaysDate的輸出。由於其輸出被重定向到一個文件,所以沒有剩餘存儲在$info中。

無論如何,沒有必要捕獲echo命令的輸出,因爲您已經在$input中擁有它。

我沒有分析整個腳本,但對於初學者我想通過只替換上面:

echo $input > jcc.$todaysDate` 

$input更換到$info任何引用。

我強烈建議縮進你的代碼;它使閱讀和維護起來更容易。

最後,您應該閱讀Csh Programming Considered Harmful。你說你的系統只有csh,但我確定它有一些版本的Bourne shell安裝爲/bin/sh