0

I have a bash script which performs a certain set of functions and uses Python 3.5 for running commands within itself. I can store the output of

 which python

in a variable but I need to set it in the file named .bash_profile so that I can call

python3.5 some_command

from within the bash script.

Thank you.

anshaj
  • 293
  • 1
  • 6
  • 24

1 Answers1

2

Use x="which python" and then eval $x.

See here: How to store a command in a variable in Linux?

If you want to store it in a file, you can always call which python >> outfile and then cat outfile to read the contents back

Or you can use sed or awk to replace some text in a config file like .bash_profile or whatever. See Find and Replace Inside a Text File from a Bash Command.

So if there was a placeholder location called PythonLocation in .bash_profile, you could do

x="which python"
eval $x
sed -i -e 's/PythonLocation/$x/g' .bash_profile