🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1679

Re: Text to command line

#1679
From: Jonathan I. Kamens
Date: Tue, 30 Oct 1990 20:24
54 lines
2018 bytes
In article <1990Oct30.183840.11819@Solbourne.COM>, johnm@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@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710
Technical Details
Message-ID: <1990Oct30.202455.4942@athena.mit.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!ucbvax!bloom-beacon!athena.mit.edu!jik
References: <1990Oct30.183840.11819@Solbourne.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!ucbvax!bloom-beacon!athena.mit.edu!jik
From: jik@athena.mit.edu (Jonathan I. Kamens)
Newsgroups: comp.unix.shell
Subject: Re: Text to command line
Message-ID: <1990Oct30.202455.4942@athena.mit.edu>
Date: 30 Oct 90 20:24:55 GMT
References: <1990Oct30.183840.11819@Solbourne.COM>
Sender: daemon@athena.mit.edu (Mr Background)
Reply-To: jik@athena.mit.edu (Jonathan I. Kamens)
Distribution: usa
Organization: Massachusetts Institute of Technology
Lines: 54