Text to command line
Jonathan I. Kamens
jik at athena.mit.edu
Wed Oct 31 07:24:55 AEST 1990
In article <1990Oct30.183840.11819 at Solbourne.COM>, johnm at Solbourne.COM (John Malia) writes:
|> Is there a way to have text that redies in a file be transferred to the
|> command line (ei. I'm running tcsh, if that makes any difference), so
|> it may be executed?
Use backquotes for command evaluation substitution, and cat the contents of
the file:
% cat test
echo frep
% eval `cat test`
frep
If you only want to execute one line from the file, use grep or sed to select
the correct line:
% cat test
echo frep
echo foobar
% eval `sed -n 2p test`
foobar
Finally, you can put the entire file into your command history using "source
-h":
% cat test
echo frep
echo foobar
% history 5
115 eval `sed -n 2p test`
116 man history
117 dirs
118 cat test
119 history 5
% source -h test
% history 5
119 history 5
120 source -h test
121 echo frep
122 echo foobar
123 history 5
% !121
echo frep
frep
Note that you have to use "eval" in the first two examples I posted above,
because of brain-damage in tcsh with deciding when to break up strings into
words (the same reason why "kill `cat list-of-PIDS`" doesn't work).
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8085 Home: 617-782-0710
More information about the Comp.unix.shell
mailing list