I have file.txt with command stored in one line (this command is valid when running in console) and I want to execute it in one line with sh like
cat file.txt | eval
what is missing? any protips?
and what if I have file with many commands (one for each line) and I want to execute only one command (one whole line)?
my first idea is:
head -n5 | tail -n1 | eval
Best Answer
eval
does not read its command string from stdin.Instead of
eval
you can use standard.
orbash
/zsh
/ksh
source
if the commands are in a file anyway:(note that it's important to add that
./
. Otherwisesource
looks forfile
in$PATH
before considering thefile
in the current directory. If in POSIX mode,bash
would not even consider thefile
in the current directory, even if not found in$PATH
).That does not work with choosing a part of the file, of course. That could be done by:
Or (with ksh93, zsh, bash):