0
我有一個bash腳本,它執行一些特定的功能,並使用Python 3.5在本身內運行命令。我可以存儲使用bash腳本設置python路徑?
which python
在一個變量的輸出,但我需要設置.bash_profile中指定的文件中,這樣我可以在bash腳本中調用
python3.5 some_command
。
謝謝。
我有一個bash腳本,它執行一些特定的功能,並使用Python 3.5在本身內運行命令。我可以存儲使用bash腳本設置python路徑?
which python
在一個變量的輸出,但我需要設置.bash_profile中指定的文件中,這樣我可以在bash腳本中調用
python3.5 some_command
。
謝謝。
使用x="which python"
然後eval $x
。
在這裏看到:How to store a command in a variable in Linux?
如果你想將其存儲在一個文件中,可以隨時撥打which python >> outfile
然後cat outfile
讀的內容回
或者你可以使用sed
或awk
來代替一些文本在像.bash_profile
或其他任何配置文件。請參閱Find and Replace Inside a Text File from a Bash Command。
所以,如果有叫.bash_profile中PythonLocation
一個佔位符的位置,你可以做
x="which python"
eval $x
sed -i -e 's/PythonLocation/$x/g' .bash_profile