$ cat somefile sleep 100 $ exec < somefile $ sleep 100
exec < somefile behave the same as
source somefile except that its invoking process terminates upon its completion?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The effect is similar, but the behaviour isn’t strictly the same.
exec < somefile connects standard input to
somefile, so the shell starts reading from that file instead of the terminal it’s currently connected to. (Well, at least bash does, Zsh behaves differently.) Effectively this results in the current shell processing the contents of
somefile, as it would with
source somefile. Once it has exhausted
somefile, the shell exits.