Bash Scripting 5 -- Arguments

  Рет қаралды 75,075

tutoriaLinux

tutoriaLinux

Күн бұрын

Пікірлер: 32
@Getoperational
@Getoperational 9 жыл бұрын
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.
@khilanpatels
@khilanpatels 4 жыл бұрын
just some extra info, $@ is all the arguments.
@moebius435
@moebius435 9 жыл бұрын
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*
@kamilkurzynowski3836
@kamilkurzynowski3836 4 жыл бұрын
Yes and you could combine it with while loop to process all the arguments.
@kamilkurzynowski3836
@kamilkurzynowski3836 4 жыл бұрын
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.
@sorover111
@sorover111 5 жыл бұрын
Can anyone help explain why the curly braces are used around line 17 .. Why can't it just be $1, $2, etc ?
@tutoriaLinux
@tutoriaLinux 5 жыл бұрын
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.
@sorover111
@sorover111 5 жыл бұрын
@@tutoriaLinux thanks man
@samuraijack5919
@samuraijack5919 4 жыл бұрын
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.
@uuu12343
@uuu12343 2 жыл бұрын
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
@prashantupadhyay6019
@prashantupadhyay6019 3 жыл бұрын
Great video How to provide file name as argument in bash script I want to sort csv file data. Please guide
@sumanth1989
@sumanth1989 7 жыл бұрын
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?
@AlDumbrava
@AlDumbrava 7 жыл бұрын
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.
@musicmansuperman
@musicmansuperman 7 жыл бұрын
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?
@youneschoukri1184
@youneschoukri1184 5 жыл бұрын
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?
@Bud_Lightyear
@Bud_Lightyear 8 жыл бұрын
I was in tune until this video. Do you have any other videos that go further in depth on Arguments?
@HigherPlanes
@HigherPlanes 9 жыл бұрын
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?
@tutoriaLinux
@tutoriaLinux 9 жыл бұрын
+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.
@HigherPlanes
@HigherPlanes 9 жыл бұрын
+tutoriaLinux Okay, that helps. I'm trying out some examples hopefully it'll sink in.
@bilalsajid96
@bilalsajid96 7 жыл бұрын
can you name some books which are available online good for bash scripting!
@tutoriaLinux
@tutoriaLinux 7 жыл бұрын
This is all you need: tldp.org/LDP/abs/html/
@andreaaldrich4046
@andreaaldrich4046 7 жыл бұрын
When I do the ourfilename part, the output I get is "-bash". This is making my crazy! What is wrong?
@andreaaldrich4046
@andreaaldrich4046 7 жыл бұрын
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?
@ArcaneFuror
@ArcaneFuror 6 жыл бұрын
@@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.
@Cespasbeau
@Cespasbeau 5 жыл бұрын
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}.
@janzaibmbaloch5484
@janzaibmbaloch5484 5 жыл бұрын
Cool!!!, why did everyone else make it look like a rocket science?
@TechnologyGeek77
@TechnologyGeek77 6 жыл бұрын
line 17 should be: echo "The first ${num_arguments} arguments are ${1}, ${2}, ${3}."}
@piotrwln9348
@piotrwln9348 6 жыл бұрын
If you suddenly have 4 arguments instead of 3, the last one won't be printed.
@souravsingha6696
@souravsingha6696 8 жыл бұрын
thanks
@dinnerandashow
@dinnerandashow 3 жыл бұрын
"You hit the spot! ${1}, ${2}"
@dharmatejaable
@dharmatejaable 8 жыл бұрын
hey bro, bash arguments.... can u be more specific.. u just ran away with this..
@tutoriaLinux
@tutoriaLinux 8 жыл бұрын
Sure, what are you confused about?
Bash Scripting 6 -- 'If' and Testing Explained
20:04
tutoriaLinux
Рет қаралды 58 М.
Parse Command Line Positional Arguments and Flags with Bash
17:46
Nick Janetakis
Рет қаралды 2,1 М.
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
BigQuery Sandbox Setup A Step by Step Guide
6:09
Cloud & AI Analytics
Рет қаралды 1
Archiving and Compression on Linux - Basic tar Commands
16:11
tutoriaLinux
Рет қаралды 65 М.
Everything You Need to Know About $PATH in Bash
9:31
tutoriaLinux
Рет қаралды 115 М.
Writing Code That Runs FAST on a GPU
15:32
Low Level
Рет қаралды 577 М.
Using BASH Variables and Arguments
12:51
Shawn Powers
Рет қаралды 4 М.
Linux Sysadmin Basics -- Linux File Permissions
10:56
tutoriaLinux
Рет қаралды 126 М.
Using BASH Script Arguments
9:00
theurbanpenguin
Рет қаралды 39 М.
Linux Basics -- Scheduling Tasks with Cron
12:06
tutoriaLinux
Рет қаралды 132 М.
Arenas, strings and Scuffed Templates in C
12:28
VoxelRifts
Рет қаралды 102 М.
НЕ ДАМ ЕЁ В ОБИДУ😡 #shorts
0:24
Паша Осадчий
Рет қаралды 1,6 МЛН
Это лютый угар 🤣 | приколы Арсен Симонян
0:14
Арсен Симонян
Рет қаралды 294 М.
Самые простые строительные леса
0:54
Канал ИДЕЙ
Рет қаралды 1 МЛН
КОРОЧЕ ГОВОРЯ, НЕДЕЛЯ БЕЗ ТЕЛЕФОНА
3:54