5e5c459eaf
git-svn-id: svn+ssh://atelier.inf.usi.ch/home/bevilj/group-1@97 a672b425-5310-4d7a-af5c-997e18724b81
60 lines
1.1 KiB
HTML
60 lines
1.1 KiB
HTML
---
|
|
layout: page
|
|
category-page: scripts
|
|
category-title: Scripting
|
|
tags: redirect output input
|
|
author: Dario Rasic
|
|
title: Redirection
|
|
---
|
|
<br>
|
|
<!-- Output redirection text -->
|
|
<h2>Output as input</h2>
|
|
|
|
<p>To redirect a certain output of the command-line we have to use the symbol ">".<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 ">>" symbols:</p>
|
|
|
|
<pre>
|
|
cat hello.txt
|
|
Sun
|
|
echo "Moon" >> hello.txt
|
|
cat hello.txt
|
|
Sun
|
|
Moon
|
|
</pre>
|
|
|
|
<!-- Input redirection text -->
|
|
<h2>Input as output</h2>
|
|
|
|
To redirect an input from a file for a command, the symbol "<" is used.
|
|
|
|
<pre>
|
|
echo < $(cat hello.txt)
|
|
Sun
|
|
Moon
|
|
</pre>
|
|
|
|
This is particularly useful when chaining commands.
|
|
|
|
<br>
|
|
|
|
<!-- Chaining command text -->
|
|
<h2>Chaining</h2>
|
|
<br>
|
|
<h1>To be completed</h1>
|
|
|
|
</p>
|