Donald Trump veered toward a shutdown of the federal government by vowing on Thursday not to sign a stopgap spending bill passed by the Republican majority in the Senate, taking his colleagues by surprise and catching many legislators who have already left town for the holiday break unawares.