let fold_pathnames f x =
let rec spec = function
| N | A _ | Sh _ | V _ | Quote _ | T _ -> fun acc -> acc
| P p | Px p -> f p
| S l -> List.fold_right spec l
in
let rec cmd = function
| Nop -> fun acc -> acc
| Echo(_, p) -> f p
| Cmd(s) -> spec s
| Seq(s) -> List.fold_right cmd s in
cmd x