python -c vs python –

The main flaw of using a here document is that the script’s standard input will be the here document. So if you have a script which wants to process its standard input, python -c is pretty much your only option. On the other hand, using python -c ‘…’ ties up the single-quote for the shell’s … Read more

Heredoc in a Makefile?

Another GNU Make solution. You can do it using the define and export commands as follows: define GITIGNOREDS *.o depend endef SRCS = $(wildcard [a-z]*.c) EXES = $(SRCS:.c=) export GITIGNOREDS .gitignore: $(SRCS) echo $(EXES) | sed ‘s/ /\n/g’ > $@ echo “$$GITIGNOREDS” >> $@ You have to be careful of make expansions (i.e. $(x)) inside … Read more

Using && after a heredoc in bash

Chaining commands in a single line You can put the control operator && right after the EOF word in your here document and you can chain more than one command: cat > file <<-EOF && echo -n “hello ” && echo world It will wait for your here-document and then will print hello world. Example … Read more