2
我有一个makefile,我想从中调用一个shell脚本,它执行某些操作并将结果返回给makefile。将参数从makefile传递到shell脚本中并获取结果?
详细描述: -
从我化妆的文件,我所说的shell脚本如下: -
source = $(PWD)
target = $(ROOT)
SCRIPT:= /home/........./temp.sh
FUNCTION:=$(shell $(SCRIPT $source $target))`
Shell脚本 “temp.sh”: -
source=$1
target=$2
echo There are $# arguments to $0: $*
common_part=$source # for now
result="" # for now
while [[ "${target#$common_part}" == "${target}" ]]; do
common_part="$(dirname $common_part)"
if [[ -z $result ]]; then
result=".."
else
result="../$result"
fi
done
if [[ $common_part == "/" ]]; then
result="$result/"
fi
forward_part="${target#$common_part}"
if [[ -n $result ]] && [[ -n $forward_part ]]; then
result="$result$forward_part"
elif [[ -n $forward_part ]]; then
result="${forward_part:1}"
fi
echo "Result=$result"
- 我没有看到Shell-Script的“回声”,可能是什么原因?
- 我怎样才能得到结果回makefile?
- 这是从make-file调用脚本的正确方法吗?
我是这方面的新手。
感谢您的回答。当我运行上面的命令,我得到以下错误:temp.sh:命令未找到 temp.sh是在我的当前目录中。我alos尝试scipt的价值./temp.sh但仍然得到相同的错误。我还错过了什么吗?请纠正我错误的地方。 – user1799483
从这个上下文无法判断。也许用更具体的细节发布一个单独的问题。 – tripleee
在makefile中,每个脚本都在子shell下运行。正如你在运行脚本之前所看到的'shell'一样。所以我建议做'cd'到你的工作目录,然后运行脚本。 例如 $(shell cd $(WORKING_DIR); ./$(SCRIPT_name)$(source)$(target)) – Omkar