bash expansion fix for writing the to files