2018-11-10 21:05:37 +00:00
|
|
|
---
|
|
|
|
layout: page
|
|
|
|
category-page: scripts
|
|
|
|
category-title: Scripting
|
2018-11-11 12:33:39 +00:00
|
|
|
tags: redirect output input
|
2018-11-10 21:05:37 +00:00
|
|
|
author: Dario Rasic
|
|
|
|
title: Redirection
|
|
|
|
---
|
2018-11-12 10:47:50 +00:00
|
|
|
<p>
|
|
|
|
<h3>Output as input</h3>
|
2018-11-10 21:05:37 +00:00
|
|
|
|
|
|
|
<p>To redirect a certain output of the command-line we have to use the symbol ">".<br>
|
|
|
|
|
2018-11-12 10:47:50 +00:00
|
|
|
In this case, we will use a file named <i>hello.txt</i>, in which we want to insert
|
2018-11-10 21:05:37 +00:00
|
|
|
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:
|
2018-11-12 10:47:50 +00:00
|
|
|
|
2018-11-10 21:05:37 +00:00
|
|
|
<pre>
|
|
|
|
cat hello.txt
|
2018-11-12 10:47:50 +00:00
|
|
|
Sun
|
2018-11-10 21:05:37 +00:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
If we want to append a certain output to an existing file,
|
|
|
|
we just have to use ">>" symbols:</p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
cat hello.txt
|
2018-11-12 10:47:50 +00:00
|
|
|
Sun
|
2018-11-10 21:05:37 +00:00
|
|
|
echo "Moon" >> hello.txt
|
|
|
|
cat hello.txt
|
2018-11-12 10:47:50 +00:00
|
|
|
Sun
|
|
|
|
Moon
|
2018-11-10 21:05:37 +00:00
|
|
|
</pre>
|
|
|
|
|
2018-11-11 12:33:39 +00:00
|
|
|
<!-- Input redirection text -->
|
2018-11-12 10:47:50 +00:00
|
|
|
<h3>Input as output</h3>
|
2018-11-10 21:05:37 +00:00
|
|
|
|
|
|
|
To redirect an input from a file for a command, the symbol "<" is used.
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
echo < $(cat hello.txt)
|
2018-11-12 10:47:50 +00:00
|
|
|
Sun
|
|
|
|
Moon
|
2018-11-10 21:05:37 +00:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
This is particularly useful when chaining commands.
|
|
|
|
|
2018-11-11 12:33:39 +00:00
|
|
|
<br>
|
2018-11-10 21:05:37 +00:00
|
|
|
|
2018-11-11 12:33:39 +00:00
|
|
|
<!-- Chaining command text -->
|
2018-11-12 10:47:50 +00:00
|
|
|
<h3>Chaining</h3>
|
2018-11-11 12:33:39 +00:00
|
|
|
<br>
|
2018-11-10 21:05:37 +00:00
|
|
|
<h1>To be completed</h1>
|
|
|
|
|
|
|
|
</p>
|