Shell脚本从文件中读取变量并在perl脚本中使用它

问题描述 投票:1回答:1

我想编写一个shell脚本,它读取文件并使用该文件的列作为perl脚本的输入。 perl脚本遍历文件(number1,number2),提取ID并将其写入新文件。如果我在命令行中使用它,perl脚本工作正常,但是,我的问题是如何编写shell脚本以使用我的input_file中的变量作为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"
bash shell
1个回答
2
投票

更换

$number_ID.ext

${number}_ID.ext

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

© www.soinside.com 2019 - 2024. All rights reserved.