如何将常量从 python 文件加载到 bash 脚本?

the*_*tor 1 python bash

我有一个 python 文件,其中维护了一堆常量值,

constant_value = 5
constant_address = '127.0.0.1'
constant_file_path = '/home/user/work'
Run Code Online (Sandbox Code Playgroud)

我正在编写一个将使用这些常量的 bash 脚本,但我不想走使用配置文件来保存这些值或它们都可以从中获取的内容的路线,我想将这些常量保留在python 文件。

我如何将这些常量读入我的 bash 脚本中以供使用?

我在网上找到了一些类似的想法,但我有点困惑,例如某些常量是 int,而其他常量是字符串等是否会出现任何问题。

For*_*Bru 5

只需删除空格 - 你就拥有了一个在 Python 和 BASH 中都有效的“多语言”文件:

constant_value=5
constant_address='127.0.0.1'
constant_file_path='/home/user/work'
Run Code Online (Sandbox Code Playgroud)

然后在 BASH 中:

constant_value=5
constant_address='127.0.0.1'
constant_file_path='/home/user/work'
Run Code Online (Sandbox Code Playgroud)