How can I send characters to a command as though they came from a file?
For example I tried:
wc < "apple pear orange"
-bash: apple pear orange: No such file or directory
|
How can I send characters to a command as though they came from a file? For example I tried:
|
||||
|
|
|
In shells that support here strings, including
|
|||||
|
|
Two other approaches (which allow multiple-line input with no extra effort):
|
|||||
|
|
you can use a pipe
|
|||||
|
|
Although there are several valid solutions here, another syntax that can be useful sometimes, is to run a command in This can be useful when you're doing something like comparing long strings of text, or if you want to diff some content that's not in a file. For example, comparing the hosts files on two nodes without having to copy the hosts file to the localhost:
The It's an easier way to create more than 1 input "file" to a command than trying to use multiple here docs, or trying to echo multiple commands to a pipeline to the final command. |
|||||
|
|
You may want to use something similar to expect. Following is a simple example of opening a remote telnet session, waiting for the prompt, send some data, wait for a response, sleep and exit.
|
||||
|
|