2018-11-11 12:17:16 +00:00
|
|
|
---
|
|
|
|
layout: page
|
|
|
|
category-page: scripts
|
|
|
|
category-title: Scripting
|
|
|
|
tags: command base echo cat grep
|
|
|
|
author: Dario Rasic
|
|
|
|
title: Script Base Commands
|
|
|
|
---
|
2018-11-16 19:47:01 +00:00
|
|
|
<!-- Echo command text -->
|
2018-11-12 19:14:49 +00:00
|
|
|
<h3>Echo</h3>
|
2018-11-11 12:17:16 +00:00
|
|
|
<p>This command print as output its entire argument on the command-line.<br>
|
|
|
|
It could be used with variables, like in the following example:<br>
|
|
|
|
|
|
|
|
<pre>
|
2018-11-16 19:47:01 +00:00
|
|
|
example="this is an example"
|
2018-11-11 12:01:25 +00:00
|
|
|
|
2018-11-16 19:47:01 +00:00
|
|
|
echo $example
|
|
|
|
this is an example
|
|
|
|
</pre>
|
2018-11-11 12:01:25 +00:00
|
|
|
|
2018-11-16 19:47:01 +00:00
|
|
|
<!-- Cat command text -->
|
2018-11-12 19:14:49 +00:00
|
|
|
<h3>Cat</h3>
|
2018-11-11 12:17:16 +00:00
|
|
|
|
2018-11-16 19:47:01 +00:00
|
|
|
This command prints the content of a certain file as an output on the
|
|
|
|
command-line.<br>
|
|
|
|
|
|
|
|
As example, we could imagine a simple text file in nano named "Hello", which contains
|
|
|
|
the line "Hello World".<br>
|
|
|
|
So, our command example will look like this:<br>
|
2018-11-11 12:17:16 +00:00
|
|
|
|
|
|
|
<pre>
|
2018-11-16 19:47:01 +00:00
|
|
|
nano Hello
|
|
|
|
cat Hello
|
|
|
|
Hello World
|
2018-11-11 12:17:16 +00:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
2018-11-16 19:47:01 +00:00
|
|
|
<!-- Grep command text -->
|
2018-11-12 19:14:49 +00:00
|
|
|
<h3>Grep</h3>
|
2018-11-11 12:17:16 +00:00
|
|
|
|
2018-11-16 19:47:01 +00:00
|
|
|
This one behaves very similarly to the previus one, but in this case it prints only
|
|
|
|
the lines matching a certain pattern.<br>
|
|
|
|
In this we could imagine a certain text file "animals", which contains a list of animal-names.
|
2018-11-11 12:17:16 +00:00
|
|
|
|
|
|
|
If we want to select only the animals whose name begins with the letter "d", we will write this:<br>
|
|
|
|
|
2018-11-16 19:47:01 +00:00
|
|
|
<pre>
|
|
|
|
grep "D" animals
|
|
|
|
Deer
|
|
|
|
Dragon
|
|
|
|
Dinosaur
|
|
|
|
Dog
|
|
|
|
Dolphin
|
2018-11-11 12:17:16 +00:00
|
|
|
</pre>
|