move check before expand — expanded file path could contain "$...$"