0

I want to automate a specific task, and I have a bash file that I want to read data from user arguments by running the script

bash my_script.sh /etc/??? path/dst

till now, I'm getting the data in my script by access to positional parameters ($1, $2) and variables, and that's fine.

But inside the script, I want to run a python program. So...

python test.py arg1 arg2 arg3

the things is, I have to read the data via python and access the output in my_script.sh

There is a constraint that I shouldn't create a file on the system. So I wonder about using export, but export is volatile since it's storing the variable till that process is opened and when I get back to my_script.sh, there isn't any clue of that data also I have no privilege to write my variable, and it's data on ~/.bashrc.

Also, I have read this and this, but they don't work the way I wanted.

if you regard the way I'm doing it, is wrong, let me know, please.

amkyp
  • 107
  • 1
  • 9
  • It's not clear what you are asking. Your script can capture or otherwise parse the output of `test.py` as it writes to standard output. – chepner Aug 14 '19 at 16:02
  • The python app that I want to run inside the script is not dependent on the `script`. Also in the `script`, I want to have access to data I processed in python app, as I said `export` can save any data for me but it's not accessible after the line of executed python app, I mean in the rest of the script I have no access to export variables. Can I parse the standard output? How? – amkyp Aug 14 '19 at 16:18
  • 2
    `output=$(python test.py arg1 arg2 arg3)`, then do what you want with `$output`. `export` only passes information from a parent to a child process, not the other direction. – chepner Aug 14 '19 at 16:27

1 Answers1

1

Thanks to @chepners comment, the solution was using $() instead of using export.

As it's mentioned in comments :

export only passes information from a parent to a child process, not the other direction.

So one of the correct ways to get an output from other application within your script is as follows:

output=$(python test.py arg1 arg2 arg3)
amkyp
  • 107
  • 1
  • 9