So let's make some script where we can use vinyl.
Great file called print as age on the first line start shoving been Bash and what we are going to build
here.
We will create a script for a reading.
Or maybe it would be better to say for printing files which will display also
line numbers.
So basically we are going to build something similar to copy command but we will also line numbers script
to take only one argument and that will be filed by.
So we can start with argument check if number of arguments is different from one
then we can fit into zero.
Exactly.
One argument is needed
around the live sign is 0 which is in our script which is our script name.
And this will be followed by file path.
And of course exit rate start those run here.
Now we can assign value of that first argument into a variable called Fireline
and as we need to count blind numbers we need some counters so craved variable count and assigned number
1 to it.
Now if actually reading we can write.
While read line we can use an other different variable name as for example Vohra but the convention
here is to line
and for each line we will perform some commands between keyboards do and dumb.
So we will print a line number represented by variable count
and then we will print on the same line.
The actual line from file
and of course we need to increase Kantar here.
So we see correct lines and line numbers.
Now we need to provide some data into viable.
So we will direct our file pop into vinyl loops standart input
scrape is down but it would be nice to do some checking if provided argument is an existing file
so we can firstly create some command about it.
Check
if provided command
is efile.
So if file exists so I am using operand and maybe better would be to ask if that file doesn't exist.
So I I will negate this by prepending exclamation mark.
And then we can print to screen file.
You have specified
does not exist.
And we can of course exit here with some status.
For example it starts to now we can save descript
ground with permissions
and we can also create some test file which then will be read by our ascript
So some data we'd like one line to something here.
Something else like the five save the file and we can now print that file by using our script
Oh that's nice.
We see all lines but we also see a line numbering.
Great.
Now let's open some bigger file for example Basford file
grade.
It is working.
I see in my case 41 lines.
Pretty amazing.
Do you remember on Tillery lecture where I told you that we have another option how to read files.
So let's try but firstly I will copy our script and rename it to print to good as a
we can open it
and just before the start of a viable up we will provide data.
Do it using pipe Soave right.
Got file name
type
and of course delete file name variable next to Dom keyboard
we can save it
and RAM to see if it is working.
And I am using passport file again.
And it is working great.
But now let's do some interesting experiment with internal field separator.
I will firstly clear the screen
then open print s age and they remove double quotation marks next to file name variable
save descript
Now Kobe.
Our test file and rename it to hello body dot text with the space between the hello and body.
Now if you want to print Hello body file
we are receiving error message Eevee printed with installed or s h
we can see content of that file so only one difference here is removed quotation marks for file name
variable.
But of-I it is behaving this way.
Firstly check the value of internal fields separator
Visi that fields are separated by space DUP and New Line as if you didn't use for a file and pop quotation
marks.
It separated our file a whole body because there is a space in the name of dead file.
But what would happen if we change into now field separator to only new lines then our file our whole
body wouldn't be separated and rendered under script.
We should see file content.
So let's experiment open into dot S H
and set into another field separator to be separated only on a new line
you noticed that at the beginning.
We have dollar sign.
If we didn't use it it would in our case separate.
Not on a new line but on a character end and also on backslash character.
So basically it means when we are using Dorsai in backslash is not a normal backslash but it is now.
Escape character which together with any character means new line.
So now save the script and add on discrete different fields separated
and it is working.
We have changed internat field separator to a new line.
So now we can see content of a whole body file because in a whole body file name is no new line character
which would separate the file name.
So advice here is to always use double quotation marks when reading files or even checking if they exist.