2018-11-14 11:36:51 +00:00
|
|
|
---
|
|
|
|
layout: page
|
|
|
|
category-page: scripts
|
|
|
|
category-title: Scripting
|
2018-11-15 20:09:21 +00:00
|
|
|
tags: variables special $ !
|
2018-11-14 11:36:51 +00:00
|
|
|
author: Dario Rasic
|
|
|
|
title: Script Special Variables
|
2018-11-18 20:38:56 +00:00
|
|
|
previous-page: pages/scripts/1-variables.html
|
|
|
|
next-page: pages/scripts/3-parameter_expansion.html
|
2018-11-14 11:36:51 +00:00
|
|
|
---
|
|
|
|
<!-- Intro -->
|
2018-11-15 20:09:21 +00:00
|
|
|
There are certain strings that we can not use in the variable-naming process.<br>
|
|
|
|
In this page we will see what actually are those strings, and what's their purpose.<br>
|
2018-11-14 21:15:38 +00:00
|
|
|
|
2018-11-14 11:36:51 +00:00
|
|
|
<h4>$$</h4>
|
2018-11-14 21:15:38 +00:00
|
|
|
To begin, we will see the simplest variable, which is the dollar sign ($).
|
|
|
|
This command simply gives us the process ID number of the current shell.<br>
|
2018-11-14 11:36:51 +00:00
|
|
|
|
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
echo $$
|
|
|
|
11480
|
2018-11-14 11:36:51 +00:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
<h4>$0</h4>
|
|
|
|
This variable will simply give us the filename of the current script.
|
|
|
|
|
|
|
|
<h4>$n</h4>
|
2018-11-14 21:15:38 +00:00
|
|
|
This variable corresponds to the arguments with which a script was invoked.
|
|
|
|
Here n is a positive number corresponding to the position of an argument.
|
2018-11-14 11:36:51 +00:00
|
|
|
|
|
|
|
<h4>$#</h4>
|
|
|
|
This variable gives us the number of arguments supplied to a script.
|
|
|
|
|
|
|
|
<h4>$!</h4>
|
|
|
|
This variable gives us the process number of the last background command.
|