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.

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

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.