put dirname outside exect