bash builtins only - 21 bytes
The X
file:
trap "echo $[++i]" 0;
EXIT
–> 0
$((...))
-> $[...]
;-)
bash builtins only - 26 bytes
Straight forward while using only bash
builtins.
IOW: No external helpers.
The X
file:
trap "echo $((++i))" exit;
(No final newline.)
Proof of the pudding:
$ bash <(cat X)
1
$ bash <(cat X X)
2
$ bash <(cat X X X)
3
Concat with or without newline inbetween:
$ cat X X ; echo # added echo compensates missing \n only
trap "echo $((++i))" exit;trap "echo $((++i))" exit;
$ bash <(cat X X)
2
$ cat X <(echo) X ; echo
trap "echo $((++i))" exit;
trap "echo $((++i))" exit;
$ bash <(cat X <(echo) X)
2