Cool to see these sorts of videos on yt. If you like sublime you might also like the editor Atom. It's opensource, actively developed, dark color scheme by default, etc. It even has the minimap feature as a package.
You could just just $1 and $2, although that could introduce quoting issues. Using string interpolation like "${1}" can avoid some of these potential issues.
Bash Scripting 5 -- Arguments My Notes: When the program is started, the filename is in what variable (bash scripting) The 0 variable (that will be the name of our script) - If you try to echo an argument that does not exist, the terminal will give you... (bash scripting) a blank line back (bash will forgive you and not throw an error) - Does bash use Zero-indexing (Does it start counting from 0,1,2 or does it start from 1,2,3?) It does not use Zero-indexing, it starts from 1,2,3 Tell me if i missed anything. Be safe and have a great day.
Shellscript does use Zero-indexing, its just that the zeroth position is like python - it is just the executable's filename itself. In this case, the scriptname
I wish you luck using those fancy things like python, they are super nice when you can use them, that is true... It is good for programmers administering in small scale, as a sysadmin you'll be dealing with a lot of legacy machines and technologies, the more critical is your infrastructure is the more you'll be dealing with old tech (including things like mainframe if you work in some fintech). I'm now learning bash deeply, cause next to bare metal C it is the only language that is compatible with all machines in my working environment. Is it a hustle? Obviously, but the reward comes in the form of the toolbox that you can probably run even on your crockpot. Don't take it wrong, great video, but I wouldn't give to much hope for the young sysadmins starting their career in terms of easy to use/easy to learn tools.
The *shift* command shifts all arguments down 1 index. *"$1"* disappears, *"$2"* takes its place, *"$3"* takes *"$2*'s place, etc. It is useful to enclose the argument parsing code in a *until* loop which tests if *"$1"* is empty as its exit condition. Not going to argue against you though: as powerful as Bash is it isn't always the correct tool for large/complex jobs. *help shift* *help until*
cannot source my .sh file to get the output of the variable it's saying bash: Hello: command not found... Do I need to install source or something? Any help please?
The 'nounset' option for your shell is set to "off". That's why your echo command didn't throw an error. Also, I was expecting a discussion of the getopts utility. Can you cover that?
I dont understand the part of running the file, can u elaborate on which directory you have saved arguments.sh and how u run it in the bash directory? Can u also automate running this script using the crontab like u explained in a previous video?
After he opened the terminal he was in ~ (his home directory). The first command he did was cd code/bash. So he's now in /home/dave/code/bash/ directory. From there he tried to run the argument.sh script but it didn't have the right permissions so he executed the chmod +x to fix that. He ran the file by simply calling (maybe opening is a better word) it (once it has execute permissions you can call the script from anywhere) ./arguments.sh means run the file arguments.sh which is located in the current directory. He can also run this file from anywhere by specifying the absolute path: /home/dave/code/bash/arguments.sh Yes you can crontab your scripts. Instead of having the echo "Hello world" >> ~/mylog.txt as the command to be run at your specified time, you would specify the absolute path to your script.
I'm still trying to understand this stuff I just can't wrap my mind around it. if I just echo $0 in a terminal I get back my current shell. What's a simple example of using $1 in a command?
+HigherPlanes This video applies mostly to scripts which have been saved in their own file, and are being run from your shell. Like you mentioned, 'echo $0' (the name of the script) will just return the name of your shell if you run it from an interactive shell session. Since your shell session isn't a program that was run with arguments, $1, $2, ...$n will be empty values. If you have that same statement in a file, though, and then run that file from your shell, you'll get the filename echoed out to you.
@@andreaaldrich4046 i know its been a year, but the answer lies in the previous video. The . Called that way is shorthand for source. And its applying it to the shell itself.
Cool to see these sorts of videos on yt.
If you like sublime you might also like the editor Atom.
It's opensource, actively developed, dark color scheme by default, etc. It even has the minimap feature as a package.
just some extra info, $@ is all the arguments.
Can anyone help explain why the curly braces are used around line 17 .. Why can't it just be $1, $2, etc ?
You could just just $1 and $2, although that could introduce quoting issues. Using string interpolation like "${1}" can avoid some of these potential issues.
@@tutoriaLinux thanks man
Bash Scripting 5 -- Arguments
My Notes:
When the program is started, the filename is in what variable
(bash scripting)
The 0 variable
(that will be the name of our script)
-
If you try to echo an argument that does not exist, the terminal will give you...
(bash scripting)
a blank line back
(bash will forgive you and not throw an error)
-
Does bash use Zero-indexing
(Does it start counting from 0,1,2 or does it start from 1,2,3?)
It does not use Zero-indexing, it starts from 1,2,3
Tell me if i missed anything.
Be safe and have a great day.
Shellscript does use Zero-indexing, its just that the zeroth position is like python - it is just the executable's filename itself. In this case, the scriptname
I wish you luck using those fancy things like python, they are super nice when you can use them, that is true... It is good for programmers administering in small scale, as a sysadmin you'll be dealing with a lot of legacy machines and technologies, the more critical is your infrastructure is the more you'll be dealing with old tech (including things like mainframe if you work in some fintech). I'm now learning bash deeply, cause next to bare metal C it is the only language that is compatible with all machines in my working environment. Is it a hustle? Obviously, but the reward comes in the form of the toolbox that you can probably run even on your crockpot. Don't take it wrong, great video, but I wouldn't give to much hope for the young sysadmins starting their career in terms of easy to use/easy to learn tools.
The *shift* command shifts all arguments down 1 index. *"$1"* disappears, *"$2"* takes its place, *"$3"* takes *"$2*'s place, etc. It is useful to enclose the argument parsing code in a *until* loop which tests if *"$1"* is empty as its exit condition. Not going to argue against you though: as powerful as Bash is it isn't always the correct tool for large/complex jobs.
*help shift*
*help until*
Yes and you could combine it with while loop to process all the arguments.
Great video
How to provide file name as argument in bash script
I want to sort csv file data.
Please guide
cannot source my .sh file to get the output of the variable
it's saying
bash: Hello: command not found...
Do I need to install source or something?
Any help please?
The 'nounset' option for your shell is set to "off". That's why your echo command didn't throw an error. Also, I was expecting a discussion of the getopts utility. Can you cover that?
I dont understand the part of running the file, can u elaborate on which directory you have saved arguments.sh and how u run it in the bash directory? Can u also automate running this script using the crontab like u explained in a previous video?
After he opened the terminal he was in ~ (his home directory).
The first command he did was cd code/bash. So he's now in /home/dave/code/bash/ directory.
From there he tried to run the argument.sh script but it didn't have the right permissions so he executed the chmod +x to fix that.
He ran the file by simply calling (maybe opening is a better word) it (once it has execute permissions you can call the script from anywhere)
./arguments.sh means run the file arguments.sh which is located in the current directory.
He can also run this file from anywhere by specifying the absolute path: /home/dave/code/bash/arguments.sh
Yes you can crontab your scripts. Instead of having the echo "Hello world" >> ~/mylog.txt as the command to be run at your specified time, you would specify the absolute path to your script.
Now to digest, test and absorb. Then, take these arguments to HR and those who call for Federal deployment projects. Can't wait to see them {sick}.
I'm still trying to understand this stuff I just can't wrap my mind around it. if I just echo $0 in a terminal I get back my current shell. What's a simple example of using $1 in a command?
+HigherPlanes This video applies mostly to scripts which have been saved in their own file, and are being run from your shell. Like you mentioned, 'echo $0' (the name of the script) will just return the name of your shell if you run it from an interactive shell session. Since your shell session isn't a program that was run with arguments, $1, $2, ...$n will be empty values.
If you have that same statement in a file, though, and then run that file from your shell, you'll get the filename echoed out to you.
+tutoriaLinux Okay, that helps. I'm trying out some examples hopefully it'll sink in.
I was in tune until this video. Do you have any other videos that go further in depth on Arguments?
Cool!!!, why did everyone else make it look like a rocket science?
When I do the ourfilename part, the output I get is "-bash". This is making my crazy! What is wrong?
Wait... I was putting ". a.sh" to execute it because that's how my teacher told us to do it, but when I put the forward slash it works... why is that?
@@andreaaldrich4046 i know its been a year, but the answer lies in the previous video. The . Called that way is shorthand for source. And its applying it to the shell itself.
can you name some books which are available online good for bash scripting!
This is all you need: tldp.org/LDP/abs/html/
line 17 should be: echo "The first ${num_arguments} arguments are ${1}, ${2}, ${3}."}
If you suddenly have 4 arguments instead of 3, the last one won't be printed.
"You hit the spot! ${1}, ${2}"
thanks
hey bro, bash arguments.... can u be more specific.. u just ran away with this..
Sure, what are you confused about?