Files
hpr-knowledge-base/hpr_transcripts/hpr0052.txt

747 lines
24 KiB
Plaintext
Raw Normal View History

Episode: 52
Title: HPR0052: UCLUG: Newbie Shell Scripting
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr0052/hpr0052.mp3
Transcribed: 2025-10-07 10:49:36
---
.
Can you film for us evening?
Alright, hey, Yom.
Hey, James, they call you James.
I'm James.
They call me James.
Welcome to the link, shoes, or scruples.
I recognize people that I know I don't recognize people, but I do recognize something.
There's people I haven't seen before, so good, that means maybe that they're newbies.
Yes, no?
We're supposed to stand up between our feet.
Yes, stand up.
I stand up.
Or we're not allowed to sit down.
No, but this is our newbie session in shale scripting.
So all right, so let's, let me get, you know,
my preparation is kind of, I just read up on,
I caught up on stuff.
I didn't really prepare slides or anything like that.
So we're going to just kind of do something on the fly.
But in this process, I'll be teaching you all how to
shale script.
All right, so let's start out and so that I can gauge what,
what we need to do.
Does everyone know what shale scripting is?
Is there anyone, let me ask it this way?
Does anyone not know what shale scripting is?
Y'all.
That's not a leading question.
That's just a lot.
Anyone not know what it is?
OK, that's good.
All right, so good.
Does anyone, all right, so, all right.
I need to know what I need to be teaching.
What does the newbies that have not used shale scripting,
have not done shale scripting, what would you like to know
exactly?
Do you know what it is?
Can they not start?
Yeah, you now have to start.
All right, you now have to start a shale script.
Here's one that I'm going to have for it.
OK.
Next to a couple of them, all right?
I've got a bunch of PHP scripts.
OK, actually.
That enclosed my sequence.
In general, I'm running at that time on web, right?
But I wrote all the interface I can run with people with.
It's a wiki.
Wiki?
No, OK, so what else?
I'll tell you all about it later.
But anyway, so I've got all these interfaces that
are basically written in PHP with my sequence in title.
And I want to schedule, I'm going to have a schedule
on the front end, and I've got five or six
together with this script that I can all, you know,
whenever.
Right.
I mean, that's basically one.
So the crime, crime, we'll call it when you want it.
Well, I'll do it's magic.
And put that into a whole thing, all of a sudden.
Right.
OK.
I guess.
All right, so what does anyone else need?
Since I have a feeling that you probably know how,
I don't know who you are.
I'm first time here.
OK.
I mean, I've done a class of people type of shell scripting.
OK.
I know a lot about it.
So then I'll need to talk to you then.
No, I'm going to vote you like that.
No, I'm sorry.
Honestly, I just thought.
That's fine, you guys on the internet.
I just came into my eye and you don't even
know what you're doing in shell script.
OK, cool.
That's cool.
I have this here.
Basic set and off without closing, you know, at 8.
Set and off.
OK.
Is that a possibility?
Set and off without closing, then it's a problem
to do to have a tolerance set with life.
Yeah, probably would be.
It's better to consider it than our regular expression set.
Yeah, they have it on books.
But OK.
Well, all right.
So shell scripting is basically taking what you do
on the command line and putting it into a script
into a program that you can run.
Everything I want is I'm sure you all know it.
That's because everyone knows what shell scripting is.
You know what shell scripting is?
Is it, that's most commonly used to have aliases?
What's that name?
Isn't there like a shell script that handles aliases?
That is a whole ton of aliases.
Like when you log in?
Yeah, I think there's a log in shell script
that I'm actually running when you log in.
Yeah, exactly.
There's the profile, the dot-pro file, dot-rc.
And that's everything.
OK, well, let's see.
All right, so will you give us an explanation on your battle?
All right, so I'm going to VIs my editor choice,
but you can use whatever you like.
So just bear with me and pay no attention
to the man behind the screen.
Yes, I think we can all put it one time.
Pops up and more.
Make it a little bit bigger.
OK, we'll do that.
Hey, that's that.
No, no, no, I've tried once, so try me.
I can.
I'll ask you.
Yeah, I want to see this on YouTube later on.
You know, I'm going to look at the cell.
I'm going to publish it.
All right, how's that?
A little easy.
You want to bigger than that?
You can erase it.
Yeah, I'll put this in.
Look, look, I can't see three little screen.
I can't really do that for all it's for.
That's a good one.
OK, we go up.
I can go up one more.
That means less to.
No, yeah, if you would, that'd be great.
All right, but there you go.
OK, can you see that then?
Do it here and take off the flag.
Oh, no.
I just like it to that.
All right, so let's see.
All right, so let's call it back up.
Back up your web thing, right?
I'll give it the dot it.
Well, yeah, it's well, I'll give it a dot bash extension
so that you know that it's a bash shell script.
Yeah, oh, you type that.
All right, let me think about it.
All right, so the first thing that you need in a shell script
is your Shebang.
Now, normally, anyone that starts with it with a sharp,
oh, this is called Shebang, because it's sharp.
Bang, Shebang.
Yummy, yummy, yummy, yummy, yummy,
Shebang, Shebang, Shebang, Shebang.
OK, so a sharp bang or pound exclamation point
tells the operating system that you
want this file to be executed by this program.
In our case, we're going to want it to be slash bin bash.
Now, the title of this is Sheal Script,
because you don't have to use bash.
There are others out there.
There's corn chill.
There's born shell.
There's normal born shell.
This is bash, it's born in shell.
Then there's Z-shell.
There's T-shell, C-shell, ash, ash, ash.
I'm not sure what it's up to.
I think that's my other C-shell.
And she sells the C-shell.
Now, R-S-A-S.
Right, right.
We're strictly shaken that that true C-type syntax.
We'll see what it all looks like.
But I'm most familiar with bash.
I used to be most familiar with T-shell, but you know.
All right, so anything that starts with a pound sign,
except for the first line, is a comment.
From the pound sign to the end of the line, is a comment.
So we're going to say just something.
Just to back up, my p2p.
OK, so that's just a comment.
That would be helpful if you put it in, because you're
going to look at it later and say, what the heck is this?
OK, so all right.
So let me stop your intro.
OK, you're going to do some kind of copy and follow.
Whatever way.
Right, under bash.
But now, let's say that I wanted to actually execute PHP.
From a shell script, I would put PHP up there,
so that it wouldn't be bad.
Sure.
Yes, OK.
Can't sorry, but it's something like that.
It's going to be like the PHP command line.
Yeah, we did.
It wouldn't know, but I have to schedule these jobs
to run automatically.
Right.
And so, I mean, I'm running PHP to the command line.
Right.
As opposed to going to the web browser.
Right, because you're not going to do it a few.
Right, when you're going to do the PHP command line,
and what I'm saying, though, is that if I wanted to reference
my speed, inside, you're not actually
called a PhD file.
Right, but actually put the PHP in this script.
I would put PHP up.
OK, now what I've got here is assume
you've got a PHP program, right?
Yeah, you want to reference here.
Now, if you want to do what you want to do,
you want to put that PHP embedded inside this shell script.
Right, right?
OK, so let's do that.
So, we want to interpret it through.
Is it user been PHP?
I would just like to use it as a bit of E and V space
to be able to think that I'll call P and V wherever it is.
And that.
I don't say I just got it with a few dashed log
in the environment or with the default.
As I say, yeah, I'm going to assume
that that's where PHP exists.
It may not.
And then you want to, let's say I'm not
as familiar with PHP, so you have to give me some help.
So, in your scripts, whatever your program is
from this point on, and I guess you
want to do it here, document.
So, in the file.
So this is your PHP stuff that gets
interpreted by PHP, and then you
got the end of your marker, which I call it, in the file.
But it doesn't have to be anything.
So, this is an example of a here document
that the shell can interpret.
Everything from this, all right.
So here is the indicator for a here document.
As everyone has anyone heard that I'm here to talk.
It's every.
Come on.
Anyone?
Anyone?
Anyone?
All right.
Who is not heard about here document?
OK.
A here document is some sort of indicator
that from this point forward is going
to be a document of sorts, of some sort, you know.
So in our case, we're going to say,
whatever you come to, that indicates the end of this file.
So this from here down, since I don't know PHP,
I'm not putting anything in there.
But this would be PHP script, whatever that is.
And then the shell sees this as, oh, that's the end of the
here document.
Here's my file to plug into PHP to execute.
Does that make sense?
Now, if I had a file, let's say,
interface.php, and that case you would probably give it
to dash f, interface.php.
So you did, what was that?
I'm assuming that dash f means execute this file.
OK.
Now, PHP may do it in another way out.
I think you speak to it.
I can't answer.
But however it is, I mean, you just take the file name
as it's parameter without it.
And share.
So we're going to somewhere that I don't know.
OK.
All of that's what I was.
But that's just one example.
It's the here document.
All right.
So let's say that from the command line, we've said, where
are you taking the OF?
You could call that anything.
Yeah, you could call it, at least over.
At this long end, at the bottom, you end up with the same thing.
It's going to basically encapsulate that information to a point.
Right.
So anything between the OF and the OF or jump and jump now?
Yeah, right.
Exactly.
Now, notice that I do not have a space here.
That's important, because if you do have a space there,
and you need to have a space, I think, down here,
I don't remember.
Just take it out.
No more.
Whatever it is.
Yeah.
Now, otherwise, you can do what you were saying.
And what you call that HP bomb interface is different.
All right.
So now that calls your HP program or something like that.
Okay.
So you basically, first of all, you hold it in the back, the shells, and then call HP from
the right.
No HP calls.
We have not.
But I mean, inside the shell.
In an inch.
All right.
So you're still, I've been back.
Yes.
Right.
So it's something in.
So whenever you have the command line or when you click your icon or whatever, it looks
at this, it says, OK, the rest of this is going to be batching.
So let's run it within a batch shell.
The batch looks at it and it comes to here.
And the batch calls HP.
Right.
HP 70 looks at it.
Arguments.
All right.
I'm going to call this.
And I'm going to interpret it.
Right.
It's up there.
Is everybody following?
Am I talking about the batch?
Because I tend to do that sometimes.
Front.
Front.
Which was in the store.
Yeah.
All right.
So let's say you want to have some arguments to, to this script.
Anyone have a certain format?
I'm going to just give it to this because it's beyond my knowledge for PHP.
So.
I'm going to say question example for you.
What was it?
There's some reason.
Okay.
So.
I'm going to make it happen.
All right.
All right.
So.
Now what I'm going to do.
I'm going to give you the one you're passing around.
If you pass white, then it's the last one.
Yeah.
It's the last one.
All right.
So.
Yeah.
So.
I do listen there.
Where do you?
You need to go anywhere.
That's what I understand.
So, there's backup.web.wav.bash.
So, all you got to do is back up, underscore, web.bash.
No, can't do that, right?
And the reason you can't do that is because, first of all,
execute your own directory, which is where I am.
Let me prove that.
I'm currently in home, Schmidt.
Hey, I like it.
So, I'm currently in this directory.
There's some files in there in this directory.
And I bet you that the path does not have this in, well, let's find out.
So, yeah, okay.
So, this is the path.
This is the, everyone know what a path is?
They would not know what a path is.
Let me ask you that.
Anyone not know what path is.
Everybody knows what a path is.
How I've done it.
So, you see that Schmidt is not here.
So, it's not going to execute.
That's one problem.
That's the one reason.
The second thing is that, if you do a long listing of the file,
Mac and I went, you will see.
Did I need to explain this?
Do you know the permissions?
It does not.
You don't know?
I do know.
You do know.
Okay.
Do you explain it?
Well, I know it to the extent R means readable, I think.
Right.
And W means writable.
And that last one is supposed to be executable.
And that's the reason that the script's not working.
Bingo.
So, we need to change it.
I'm going to want it plus X of that.
Okay.
And you're listing and it's green.
But that's just close to this shelf.
So, now I can put this directory,
run back up, dot, underscore web.bash.
And there we go.
Okay.
Do you explain it?
Too loud.
Too loud.
Too loud.
Too loud.
Too loud.
Too loud.
Too loud.
Too loud.
Too loud.
Too loud.
Too loud.
Too loud.
Okay.
Final run out.
All right.
So, you want to,
Chmod is to change the mode of the file.
These are the mode bits.
I added the executable width so that it becomes executable.
Unix is different from the other operating system.
In that,
it's not determined by the file type,
whether it's executed or not.
It's just determined by this bit,
whether it can be executed.
So, any file can be executable.
Not a good idea for all files.
If, especially if it's just a text file,
you can try to execute it.
It just goes, you know, or something.
All right.
So, now we've got execution rights for execution rights.
For the user, for the green, and all.
All right.
So, now, you see the X that I,
in order to execute from my correct directory,
which is what the thought is,
and the slash, this file.
It executed, and it gave me that.
Now, why did it give me that?
All right.
Does it?
Do I need to go into that?
Sure.
If I don't know what it need to go into,
we can do something else.
This is a newbie session.
So, please, if you don't understand,
you haven't said the echo group.
All right.
So, why didn't you do that?
Oh, my God.
Now, let's take you away.
Let's take away your arguments to the script.
Yes.
So, you see I've got, I'll send $2 and $1 and $0.
I'm just kidding.
That's pound.
I want $2.
All right.
All right.
So, I gave it the A, B, and C.
It is B, A, and then the program.
So, 0 is always going to be the program that's executing.
Then, any arguments after that go 1, 2, 3, 4.
Yes.
Until you get the 9,
and after 9, you're going to have to use
a dash as curly braces around.
And I'll do that.
So, so you can see what I'm talking about.
Unless you don't want me to take you out of this.
You'd like to see the argument.
Let me rerun at 1, 2, 3, 4, 5, 6, 7, 3, 9, 10, 11, 12.
Just for good entry.
All right.
Just.
I'm not used to quarry, so y'all bear with me, I'm a devourer guy, 5, 4, 5, 3, what's that?
I really am typing it.
What did you say?
This is sweet tea, sweet tea, I have to make my head fit fit fit fit fit.
Eric always says to give me a hard time for some reason, it's not, it's not, it's not,
it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not,
it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not,
it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not,
it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not, it's not
Now I think they must have changed this, but they used to be, it was confusion whether this is a dollar sign one with a zero after it or if this is a dollar sign 10 so what you need to do in bash is put braces around the name of your variable and then that's the, okay,
that's why I should go with this. So this is the argument variables, I guess you just say.
So other variables, you can just make your own, and then you just put something in it.
Is there a shift? That is like threes in the box. A shift there is. Yes, there is. If I wanted
to, I could just eat my own. Let's give something to you. Am I losing anyone yet?
Long time ago. All right. So, I said that long time ago. So you're really lost.
Oh, yeah. Okay. Well, they asked me the question that you wanted, that you don't understand.
Well, I mean, I'm not familiar with the scripting. Do you understand, like, the badge, and then you can see that?
Okay. That's expected. What? Have you done any examples of some scripts on there or some simple things?
Probably, I've been done here or something. We can do that. That's kind of complicated.
All right. So have you done any programming at all?
I went for a degree and I got in and out of the script and popped into it.
Okay, but you got a degree from it, right? I got a degree from it.
But you said you've done it to a degree. All right. So, then let me know what's confusing.
Well, I mean, for me, most everything, because I don't get to wrap around programming well at all.
I think, you know, really long time to get mentally to the point of knowing, you know, what you're putting in and out of this.
You know what I said?
No, this is a new recession. So, I'm sure you're not the only one that has this question. So, I'm here for you, man.
You're a little late, too. So, I mean, that's all right.
All right. So, at the very beginning.
I didn't this much good.
At the very beginning, this is a file I'm editing.
And this, I just put the output.
So, whenever it starts out, it's going to be running the bash, which is the ship born again, shell.
Which was named after Mr. Bourne.
Jason Bourne here.
No, no, no. Different words.
In you.
In you.
All right. In most scripting languages, is it time?
You just get bored.
All right.
In most scripting languages, the pound sign means a comment.
So, that's why I got the second line here.
So, it's from the pound sign to the end of the line. That's a comment.
So, it's ignored.
Except for when it's the first line.
And it's a pound and an exclamation point.
That means to the operating system, I'm going to run this file with this program.
Okay. So, this program is going to be run by bash.
Does that make sense?
Yeah, exactly.
Where?
That exclamation point.
That exclamation point.
That exclamation point.
That exclamation point.
That indicates to the operating system that this will execute this.
Okay. So, this is.
Bash is going to be running this script.
Okay.
Now, this is a pound.
So, that means this is a comment from there on.
To the end of the line.
Okay. Okay.
Tell me.
Yes.
What type of program is that?
What type of program is what?
Echo.
In Chrome.
Yeah, it's a built-in.
But built-in.
Two different types.
You'll have one set of built-in.
One set of built-in.
One set of built-in.
One set of built-in.
One set of built-in.
You've got a following statement.
You've got a user voting.
Unless is in your pad.
Unless is in your pad.
Which echo could be?
And if you're running this script,
lock it like this.
Your site would set up that absolute pad.
It's going to level it around.
Actually, can you tell its how they did it to the drill?
With a very long schedule which people are.
Well, now I'm going to really far.
Well, I mean, if you're writing a script, the one thing you want to be aware of is that the shell is there to help you.
Yes.
If you're curious as to how you're going to have to go about it.
That's paying for it.
That's the way it will look.
All right.
That's like 80 plus pages of dot.
And that's not, that's not paying for it.
All right, those?
Well, I don't know.
No, I know.
You can go on a screen at home as opposed to working and up there.
You can see all of those variables that are all those built in commands.
Built in commands are available.
You can spend your scripting.
You can talk to all of those items there.
You don't have to put a path to just simply use it.
And if you have a question about it, there's various documentation that can explain what the various things are.
Some of them are pretty straightforward.
Let me see.
Fc, you can figure out, you know, like WC is like the word counts.
You can figure out how many words are in a bottle.
So I put the word, how many characters are in a bottle?
Okay.
So.
Now, in, in bash, the variables, you know, the variables, right?
Okay, variables start with a dollar sign.
Okay.
In bash.
I'm just born shell, corn shell, t-shell, you know, just for nothing.
I think all shells.
Okay.
No one's disagreeing.
Now, in bash, the, yeah, you were here before you walked in.
In bash, whenever you call program, it's automatically signs these numeric variables.
Zero is the name of the program.
That's right.
So in our case, it's not the name of that.
Yeah.
But it's the name.
So this will print what you've got there now.
And right here, you see, I'm assigning to the variable that I called my own.
And I assign something in it.
Now, in, in, in bash and born shell, you need to not have spaces around it.
This is not C.
Otherwise, it's assuming you want the my own program.
But everything that's in a shell script, you can do all the command line, line by line.
In fact, I usually test my shell scripts by cutting and pasting this into my command line.
And see where it is.
Now, the, you got to finagle some of the variables because you're not going to have the same one through ten or whatever.
And your script may be changing your variables, and that's what I think.
Why don't you have that half of it?
$5 in front of my own when you define it.
When you define it, you do not need it.
And you should not let it in fact.
But whenever you use it after this, when you use it, you, you need it.
Because it's referencing my own.
This is where you're both defining and putting a value to it.
That's what echo means.
Echo means put to the screen.
Why are you presenting echo within all those variables?
Just to show stuff.
When it runs in the program, it's actually going to put variables after it.
And those are going to be referenced by this echo statement.
So it's hers.
See if there's numbers after the word.
Okay.
I think that's basically what he's saying.
The program is echo those numbers.
What's now the first one it is?
Right over one is the first argument.
So it's going to be a second and two and four.
Right.
Do he say is echo $8?
And then you end up being 8.
What's the response to this?
Hey, let's all go.
Hey.
All right.
It's great to hear.
Wow.
Wow.
It signifies that it's a bash grip.
That's just for me.
You can go through it.
It's not needed.
That was just for my purposes.
So that either it does a bash grip here.
The operating system is going to look
from Shabang at the beginning.
The pound exclamation point called Shabang Shabang.
All right.
So what time is it?
Seven.
Seven of seven.
I know why.
Should we continue this later or should is everyone comfortable
with shell scripting now?
Yeah.
We should continue later.
Let me ask is anybody wants to start in shell scripting?
Of various sorts.
There are a lot of good resources out there.
This is not bash, but the one that I did,
I was king of the dummies in the envelope.
Units programming for dummies.
It's a sea shell.
But it teaches you a lot of good methods.
And a lot of good ones with the stuff
is what he's talking about here.
It's very good.
But one resource is tons of resources.
There are two gods that are one is a beginning bash shell scripting,
which somebody received this past week.
And the other one is the advanced bash shell scripting.
I love it, which is very good.
And both of them are open source maintain.
So you can get to all the examples.
Okay, would anyone want to continue this next week?
Next month?
Yes, sure.
Yes, sure.
Thank you for listening to Half Republic Radio.
HPR is sponsored by Carol.net.
She'll head on over to C-A-R-O.N-T for all of her team.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.
Thank you.