1

I want to write a shell script, that reads a file and use the columns of that file as input for a perl script. The perl script is going through files (number1, number2), pulls out the ID and write those to a new file. The perl script is working fine if I use it with the command line, however, my question is how I write a shell script to use the variables in my input_file for the perl script.

My input_file looks like

number1 ID1
number2 ID2

And I use the following shell script (which is not working, so please help with this)

#!/bin/bash

input_file="$1" 

while IFS=" " read -r number ID
do
    perl extract.pl $ID $number.ext > $number_ID.ext
done < "$1"
2
  • 1
    Please take a look: shellcheck.net Commented Dec 18, 2017 at 7:46
  • Great site, I did not know it. Thanks! Commented Dec 18, 2017 at 9:14

1 Answer 1

2

Replace

$number_ID.ext

with

${number}_ID.ext

_ is a character allowed in variable names. That's why bash is looking for $number_ID. . is not allowed.

Sign up to request clarification or add additional context in comments.

1 Comment

Maybe also point out (like shellcheck.net already does) that input_file is assigned but unused.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.