我想在Makefile中添加一些变量和回显命令。这一节是:
.PHONY: run_harness
run_harness: link_dirs
@mkdir -p $(LOG_DIR)
@set -o pipefail && $(PYTHON3_CMD) code/main.py $(RUN_ARGS) --action="run_harness" 2>&1 | tee $(LOG_DIR)/stdout.txt
@set -o pipefail && $(PYTHON3_CMD) scripts/print_harness_result.py $(RUN_ARGS) 2>&1 | tee -a $(LOG_DIR)/stdout.txt我想补充一下
.PHONY: run_harness
run_harness: link_dirs
@mkdir -p $(LOG_DIR)
########
@export WRK="test"
@export startTime=$(date +%s)
@echo $(WRK), $(startTime)
########
@set -o pipefail && $(PYTHON3_CMD) code/main.py $(RUN_ARGS) --action="run_harness" 2>&1 | tee $(LOG_DIR)/stdout.txt
@set -o pipefail && $(PYTHON3_CMD) scripts/print_harness_result.py $(RUN_ARGS) 2>&1 | tee -a $(LOG_DIR)/stdout.txt但是这些导出和回显不起作用,因为输出中有,,这意味着$(WRK)和$(startTime)都是空的。我怎么才能解决呢?
更新:
以下更改
@mkdir -p $(LOG_DIR)
export WRK="3d-unet"; \
export startTime=$(date +%s); \
echo $(WRK), $(startTime) ;由于此错误而无法工作
发布于 2022-07-10 14:16:17
菜谱中的每一行都在单独的shell中执行。您需要将所有shell命令放在一行上,用分号分隔(并可能使用行继续和反斜杠换行符,以提高可读性)。您必须使用$$name引用shell变量(而不是使用make变量$(name))。请注意,make为shell替换了一个$$,并使用了一个$。
foo: bar
export x=hello y=world; \
echo "$$x" "$$y"https://stackoverflow.com/questions/72929138
复制相似问题