【问题标题】:Shell script to read variables from file and use that in perl script用于从文件中读取变量并在 perl 脚本中使用的 Shell 脚本
【发布时间】:2017-12-18 07:39:19
【问题描述】:

我想编写一个 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】:

替换

$number_ID.ext

${number}_ID.ext

_ 是变量名中允许的字符。这就是 bash 寻找$number_ID 的原因。不允许使用.

【讨论】:

  • 也许还指出(就像shellcheck.net 已经这样做了)input_file 已分配但未使用。
猜你喜欢
  • 2014-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多