We are going to touch only briefly on a parameter expansion in this lecture.
Let's clear the console first.
So but we will be covering it extensively in the later just to mention that.
So it's a feature that is more useful in shell scripts and directly on the command line.
So many of the capabilities have to do with the system's ability to store small chunks of data and to
give each chunk a name.
Many such chunks more properly called R variables are available for your examination.
So, for example, the variable user contains username to invoke parameter expansion and reveal the
contents of user.
You should do this echo dollar sign and user.
And here, as you can see here, I printed my username so to list of the to see a list of available
variables.
You can also try this print any v here and last year we will use this.
And as you can see here we have this system variables and which is called PG.
You can.
And the home directory is this our language log name is iPhone password or.
No, it's actually PWD.
Uh, here, uh, this is the working directory that we are in, and here we have, uh, information
about that.
So let's actually end this here.
Oops.
Here.
Exit this and here with Ctrl Q or for example, and as you can say, press return lock file is already
in use.
So we are use this lock file and here we are going to exit it now.
With controls.
So you may have noticed that with other types of expansion and as you can see, we have our current
working directory is p.w.d..
So we're going to clear and CD here.
And again, CD, Let's go home here and let's and let's say we are in the home here.
So as I said, if you noticed, with other types of expansion, if you mistype a pattern, the expansion
will not take place and the echo command will simply display the mistyped pattern.
So with parameter expansion, if you misspell the name of variable, the expansion will still take place
but will result in an empty string.
So for example, this.
So as you remember in previous minutes of our lecture, we printed our username with user.
But if we write it like that, Echo Sawyer here or yeah.
Sawyer So actually it's a misspelled type of the user.
WHEN Okay.
And as you can see here, we got nothing as an error and it's just an new line.
So you will also learn about the command substitution in this lecture.
So common substitution allows us to the output of a command as an expansion.
So in order to do that, we will echo.
And here in the inside the braces we will use LHS and here.
And as you can see, we got this command here.
So and one of my favorites is this here which and CP and as you can see here, we got this.
So here we pass the results of which CP as an argument to the command, thereby getting the list of
a list of the CP program without to know its full path name.
So we are not limited, just a simple commands entire pipe.
Pipelines can be used for example, and working with it.
We also have the cool thing here.
So now that we have seen how many ways the Shell can perform expansions, it's time to learn how we
can control it.
So take for example, this echo.
This is Oxley and oops, not like this.
Oh, this is Oxley Academy.
And as you can see here, this ignored all of these spaces here.
And you can also do, for example, echo the total.
Total.
Price.
Price is, for example, $100.
And here and as you can see here, the total price is zero.
So in this first example with this word splitting by the shell, removed extra whitespace from the Echo
command and the echo commands list of arguments.
So in the second example, parameter expansion substitute an empty string for the value of $101 because
it was an undefined variable.
So the shell provides a mechanism called quoting to selectively suppress unwanted expressions.
Here we also have the double quotes here, double quotes here.
So the first type of quoting we will look at is double quotes.
If a place text inside the double quotes, all the special characters used by the shell lose their special
meaning and are treated as an ordinary characters.
So the expressions are the dollar sign and backslash and backtick here.
Backtick.
So this means that the word splitting pathname expansion, titled expansion and brace expansions are
suppressed.
In this case, however, parameter expansion, arithmetic expansion and common substitution are still
carried out Using double quotes, we can cope with file names containing embedded spaces.
Let's say we were the unfortunate victim of a file called this.
Two words dot txt here.
If we try to use this on the command line, we are word splitting wood lines called the two words txt.
And if we try to use this on a command, word splitting will cause this to be treated as a two arguments
rather than the desired single argument.
So for example, I want to create a new file, for example.
Torch torch my file without question mark or something.
And here and as you can see, we created my file, which now if we write it like that, for example,
ls l my file my file dot txt.
This will take as a two arguments, but in order to do access this my file we will use double quotes
for accessing this here.
And as you can see here we access to my file here.
So there.
And as you can see now, we don't have to keep tying those pesky double quotes.
So remember, parameter expansions, arithmetic expansions and common substitution still take place
within the double quotes.
So for example, look at this.
So echo and here we will do double quotes.
So inside this double quotes we will user.
And dollar sign to.
The last two.
Two plus two.
And after that we will use a dollar sign.
And after that we will call calendar.
So this call is actually calendar, which we will show us and calendar is actually not installed.
So let's actually install calendar.
So app sudo apt, apt, install ankle and I don't think it will take much time because it's I think
it's just.
Here.
And here.
This is just a 69kB of file size, and it's already installed here.
So now let's clear our files.
Clear and use previous here.
And as you can see here, we got calendar on it on the screen.
So we shall take a moment to look at the effect of double quotes on common substitutions.
So first, let's look a little deeper at words, how words splitting works.
In earlier lectures, we saw how words splitting appears to remove extra spaces of in our text.
For example, this is this is Oxley and Here Academy.
And as you can see here, it just ignored our text.
So by default, the word splitting looks for the presence of a space tabs and newlines in line characters
line feed characters and actually and treats them as delimiters between words.
So this means unquoted space tabs and newlines are not considered to be part of the text, so they serve
only as separators because they separate the words into different arguments.
Our example command line contains a comment followed by for district arguments.
If we add like this, for example, add the quotation marks in the start of the end line and as you
can see here, it is not ignoring our.
The new lines or spaces as it did in our previous, like previous example.