use inreplace and bin.mkdir as suggested by adamv