theshell.ch/site/pages/scripts/redirection.html

56 lines
984 B
HTML
Raw Normal View History

---
layout: page
category-page: scripts
category-title: Scripting
tags: reditect output input
author: Dario Rasic
title: Redirection
---
<h2>Output as input</h2>
<p>To redirect a certain output of the command-line we have to use the symbol "&gt;".<br>
In this case, we will use a file named "<i>hello.txt</i>", in which we want to insert
a certain output ("Sun" in this case):<br>
<pre>
echo "Sun" > hello.txt
</pre>
So if we print the content of the file in our command-line, the output will be the following:
<pre>
cat hello.txt
Sun
</pre>
If we want to append a certain output to an existing file,
we just have to use "&gt;&gt;" symbols:</p>
<pre>
cat hello.txt
Sun
echo "Moon" >> hello.txt
cat hello.txt
Sun
Moon
</pre>
<h2>Input as output</h2>
To redirect an input from a file for a command, the symbol "&lt;" is used.
<pre>
echo < $(cat hello.txt)
Sun
Moon
</pre>
This is particularly useful when chaining commands.
<h2>Chaining</h2>
<h1>To be completed</h1>
</p>