2017-12-18 122 views
1

我想编写一个shell脚本,它读取一个文件并将该文件的列用作perl脚本的输入。 perl脚本正在通过文件(number1,number2),提取ID并将它们写入新文件。如果我在命令行中使用perl脚本,perl脚本工作正常,但是,我的问题是如何编写shell脚本来在我的input_file中为perl脚本使用变量。Shell脚本从文件读取变量并在perl脚本中使用

我INPUT_FILE看起来像

number1 ID1 
number2 ID2 

,而且我用下面的shell脚本(这是行不通的,所以请这方面的帮助)

#!/bin/bash 

input_file="$1" 

while IFS=" " read -r number ID 
do 
    perl extract.pl $ID $number.ext > $number_ID.ext 
done < "$1" 
+1

请看看:http://www.shellcheck.net/ – Cyrus

+0

伟大的网站,我不知道它。谢谢! – Gravel

回答

2

更换

$number_ID.ext 

${number}_ID.ext 

_是变量名称中允许的字符。这就是为什么bash正在寻找$number_ID.是不允许的。

+0

也可能指出(像http://shellcheck.net/已经这样),input_file被赋值但未被使用。 – tripleee