theshell.ch/site/pages/scripts/redirection.html
bevilj 67a86268c1 proj: code review 1.1
git-svn-id: svn+ssh://atelier.inf.usi.ch/home/bevilj/group-1@130 a672b425-5310-4d7a-af5c-997e18724b81
2018-11-12 10:47:50 +00:00

60 lines
1.1 KiB
HTML

---
layout: page
category-page: scripts
category-title: Scripting
tags: redirect output input
author: Dario Rasic
title: Redirection
---
<p>
<h3>Output as input</h3>
<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>
<!-- Input redirection text -->
<h3>Input as output</h3>
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.
<br>
<!-- Chaining command text -->
<h3>Chaining</h3>
<br>
<h1>To be completed</h1>
</p>