Meeran
Meeran

Reputation: 91

How would I redirect both Standard output and Standard input of a command to a text file in one line?

How would I redirect both Standard output and Standard input of a command to a text file in one line, and would the Standard input of a command such as "ls" be "ls", and if I redirected the standard input of ls to a file, would these characters appear in the file?

Upvotes: 0

Views: 180

Answers (2)

user4386814
user4386814

Reputation:

You can use the script command

Input

$ script
Script started, file is typescript
sh-4.1$ ls
bar.txt  baz.txt  foo.txt  typescript
sh-4.1$ exit
exit
Script done, file is typescript

Output

$ cat typescript
Script started on Sat Dec 27 13:49:33 2014
sh-4.1$ ls
bar.txt  baz.txt  foo.txt  typescript
sh-4.1$ exit
exit

Script done on Sat Dec 27 13:49:40 2014

explainshell.com - script

Upvotes: 1

Barmar
Barmar

Reputation: 781004

To redirect both input and output, just use both redirections:

command < inputfile > outputfile

If the command doesn't read from its standard input, then the input redirection will have no effect. For instance, ls doesn't use its input, it just processes command line arguments.

Upvotes: 0

Related Questions