Pass input and output files desired PATH to a binary in bash

In a bash script called through shell in some directory ($PWD), there is a line where I need to call an executable located at $PWD/bin so that it reads a input file located at $PWD/inputfiles and the resulting output files are stored in $PWD/output.

Can this be achieved?

PS: Now if I am at

cd /home/user

I do

./run config.inp output.dat

with config.inp being at /home/user

config.inp reads files data.txt and lines.txt which are in the same directory.

Now I want to read from /home/user/input and write the output files to /home/user/output

and I try

./run input/config.inp

it says

error, data.txt not found

As the problem is described, this will do it:

bin/executable < inputfiles/input > output/output

If the problem is really that bin/executable creates files in the current directory without allowing the user to specify the input and output files, then it will be a little more complicated. What you would probably want to do instead is:

cd output
ln -s ../inputfiles/input
../bin/executable
rm input

This will create a symbolic link to inputfiles/input from within the output directory, and then delete it later. If you want to eliminate the chance of collisions with files in the output directory, then you need to create a temporary directory with something like TMPDIR = $(mktemp -d) , do everything there, and then copy it back to $OLDPWD/output .

链接地址: http://www.djcxy.com/p/56816.html

上一篇: 将参数传递给Bash函数

下一篇: 将输入和输出文件所需的PATH传递给bash中的二进制文件