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-18 20:38:56 +00:00
|
|
|
next-page: pages/scripts/1-variables.html
|
2018-11-11 12:17:16 +00:00
|
|
|
---
|
2018-11-16 19:47:01 +00:00
|
|
|
<!-- Echo command text -->
|
2018-11-12 19:14:49 +00:00
|
|
|
<h3>Echo</h3>
|
2018-11-19 15:05:42 +00:00
|
|
|
<p>This command prints its entire argument as output on the command-line.<br>
|
|
|
|
It can be used with variables, like in the following example:<br>
|
2018-11-11 12:17:16 +00:00
|
|
|
|
|
|
|
<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-19 15:05:42 +00:00
|
|
|
This command prints the content of a certain file as output on the
|
2018-11-16 19:47:01 +00:00
|
|
|
command-line.<br>
|
|
|
|
|
2018-11-19 15:05:42 +00:00
|
|
|
For example, we could imagine a simple text file in nano named "Hello", which contains
|
2018-11-16 19:47:01 +00:00
|
|
|
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>
|