1

I have written a bash script which calls another script by passing it an argument. The argument in this case is a file that contains a few lines.

I do something like this:

#! /bin/bash

`python script.py -i input.txt /path/to/somefile`

now, input.txt contains lines like:

something 1
something 2
something 3

The problem here is that each line of input.txt is evaluated as a program itself by the bash script instead of being passed as it is to the script.py program.

so, script.py program expects a file with 3 lines as input as shown above but instead receives some other input (result of evaluating something 1, something 2 and so on).

how can I pass this file as an argument to script.py?

if I invoke script.py outside the bash script like this:

python script.py -i input.txt /path/to/somefile

it works good. script.py reads one line from input.txt at a time and operates on it.

1
  • Just curious, why did you think backticks are needed in bash? Perl background? Commented Oct 26, 2013 at 15:13

1 Answer 1

3

Remove the backticks around python command... I think you are misinterpreting what happens, python output is evaluated as a command, not input.txt.

Backticks perform command substitution, same as $( ... ). Discussed here for example, and here. Usually it is used as argument to command, like ls -l $(cat filelist.txt), but it works as entire command too. Though if you blindly execute whatever output of some program, you better be sure you trust the output to be correct, trustworthy and free of any security holes which would allow shell command injection (read: don't do it ;-)...

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.