有时候shell脚本需要输出TAB键,如脚本生成Makefile

makefile() {
cat << EOF
all:build
build:
	make all -C submodules/build
clean:
	make clean -C submodules/build
veryclean:
	make veryclean -C submodules/build
install:
	mkdir -p $PREFIX/include
	mkdir -p $PREFIX/lib
	cp -rf $SOURCE/include/* $PREFIX/include
	cp -rf $SOURCE/lib/* $PREFIX/lib

EOF
}

info 'Generate Makefile ...'
makefile > Makefile
info 'Generate successed.'

以上生成的Makefile是有问题的,非TAB键,而应该使用如下方案


makefile() {
cat << EOF
all:build
build:
`printf "\t"`make all -C submodules/build
clean:
`printf "\t"`make clean -C submodules/build
veryclean:
`printf "\t"`make veryclean -C submodules/build
install:
`printf "\t"`mkdir -p $PREFIX/include
`printf "\t"`mkdir -p $PREFIX/lib
`printf "\t"`cp -rf $SOURCE/include/* $PREFIX/include
`printf "\t"`cp -rf $SOURCE/lib/* $PREFIX/lib

EOF
}

info 'Generate Makefile ...'
makefile > Makefile
info 'Generate successed.'