eval does not read its command string from stdin.
eval "$(cat file.txt)"
# or easier, in ksh/bash/zsh
# usually you cannot be sure that a command ends at the end of line 5
eval "$(head -n 5 file.txt)"
eval you can use standard
source if the commands are in a file anyway:
(note that it's important to add that
source looks for
$PATH before considering the
file in the current directory. If in POSIX mode,
bash would not even consider the
file in the current directory, even if not found in
That does not work with choosing a part of the file, of course. That could be done by:
head -n 5 file.txt >commands.tmp
Or (with ksh93, zsh, bash):
source <(head -n 5 file.txt)