Тёмный

Shell Scripting Tutorial for Beginners 4 - Pass Arguments to a Bash-Script 

ProgrammingKnowledge
Подписаться 1,8 млн
Просмотров 369 тыс.
50% 1

Passing arguments to a shell script
Any shell script you run has access to (inherits) the environment variables accessible to its parent shell. In addition, any arguments you type after the script name on the shell command line are passed to the script as a series of variables.
The following parameters are recognized:
$*
Returns a single string (``$1, $2 ... $n'') comprising all of the positional parameters separated by the internal field separator character (defined by the IFS environment variable).
$@
Returns a sequence of strings (``$1'', ``$2'', ... ``$n'') wherein each positional parameter remains separate from the others.
$1, $2 ... $n
Refers to a numbered argument to the script, where n is the position of the argument on the command line. In the Korn shell you can refer directly to arguments where n is greater than 9 using braces. For example, to refer to the 57th positional parameter, use the notation ${57}. In the other shells, to refer to parameters with numbers greater than 9, use the shift command; this shifts the parameter list to the left. $1 is lost, while $2 becomes $1, $3 becomes $2, and so on. The inaccessible tenth parameter becomes $9 and can then be referred to.
$0
Refers to the name of the script itself.
$#
Refers to the number of arguments specified on a command line.
★★★Top Online Courses From ProgrammingKnowledge ★★★
Python Programming Course ➡️ bit.ly/2vsuMaS ⚫️ bit.ly/2GOaeQB
Java Programming Course ➡️ bit.ly/2GEfQMf ⚫️ bit.ly/2Vvjy4a
Bash Shell Scripting Course ➡️ bit.ly/2DBVF0C ⚫️ bit.ly/2UM06vF
Linux Command Line Tutorials ➡️ bit.ly/2IXuil0 ⚫️ bit.ly/2IXukt8
C Programming Course ➡️ bit.ly/2GQCiD1 ⚫️ bit.ly/2ZGN6ej
C++ Programming Course ➡️ bit.ly/2V4oEVJ ⚫️ bit.ly/2XMvqMs
PHP Programming Course ➡️ bit.ly/2XP71WH ⚫️ bit.ly/2vs3od6
Android Development Course ➡️ bit.ly/2UHih5H ⚫️ bit.ly/2IMhVci
C# Programming Course ➡️ bit.ly/2Vr7HEl ⚫️ bit.ly/2W6RXTU
JavaFx Programming Course ➡️ bit.ly/2XMvZWA ⚫️ bit.ly/2V2CoAi
NodeJs Programming Course ➡️ bit.ly/2GPg7gA ⚫️ bit.ly/2GQYTQ2
Jenkins Course For Developers and DevOps ➡️ bit.ly/2Wd4l4W ⚫️ bit.ly/2J1B1ug
Scala Programming Tutorial Course ➡️ bit.ly/2PysyA4 ⚫️ bit.ly/2PCaVj2
Bootstrap Responsive Web Design Tutorial ➡️ bit.ly/2DFQ2yC ⚫️ bit.ly/2VoJWwH
MongoDB Tutorial Course ➡️ bit.ly/2LaCJfP ⚫️ bit.ly/2WaI7Ap
QT C++ GUI Tutorial For Beginners ➡️ bit.ly/2vwqHSZ
★★★ Online Courses to learn ★★★
Get 2 FREE Months of Unlimited Classes from skillshare - skillshare.eqcm.net/r1KEj
Data Science - bit.ly/2lD9h5L | bit.ly/2lI8wIl
Machine Learning - bit.ly/2WGGQpb | bit.ly/2GghLXX
Artificial Intelligence - bit.ly/2lYqaYx | bit.ly/2NmaPya
MERN Stack E-Degree Program - bit.ly/2kx2NFe | bit.ly/2lWj4no
DevOps E-degree - bit.ly/2k1PwUQ | bit.ly/2k8Ypfy
Data Analytics with R - bit.ly/2lBKqz8 | bit.ly/2lAjos3
AWS Certification Training - bit.ly/2kmLtTu | bit.ly/2lAkQL1
Projects in Java - bit.ly/2kzn25d | bit.ly/2lBMffs
Machine Learning With TensorFlow - bit.ly/2m1z3AF | bit.ly/2lBMhnA
Angular 8 - Complete Essential Guide - bit.ly/2lYvYRP
Kotlin Android Development Masterclass - bit.ly/2GcblsI
Learn iOS Programming Building Advance Projects - bit.ly/2kyX7ue
★★★ Follow ★★★
My Website - www.codebind.com
DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!

Опубликовано:

 

3 мар 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 89   
@marklambert2777
@marklambert2777 4 года назад
Good idea to show two screens, one with the editing and the other with output at the same time. Not many tutorials bother doing that.
@mamtachahal1277
@mamtachahal1277 4 года назад
One of the best tutorials on Shell Scripting out there. Thanks a lot man, Appreciate your effort.
@charlesklein7232
@charlesklein7232 4 года назад
i have seen alot of videos and your are the most educational. you are the first person who video i saw after i went from w2k to Linux. you showed me how to load things. thank you!
@ShwetaSingh-ug2tk
@ShwetaSingh-ug2tk 3 года назад
best videos on shell scripting seen till date. Thanks a ton!!
@orestisiona6697
@orestisiona6697 2 года назад
This whole series is amazing. Thank you so much!. Viewing this in 2021!
@Onomandah
@Onomandah 5 лет назад
So easy to understand. Thank you!!
@pmrm100
@pmrm100 2 года назад
well, you have made shell scripting as easy as possible.
@insoucyant
@insoucyant Год назад
Amazing Series. Thank You!!
@balramsharma5887
@balramsharma5887 6 лет назад
thank u so much sir ...great job
@nilesh122n
@nilesh122n 6 лет назад
very good,really helpful for me
@fatehsinghsunny
@fatehsinghsunny 6 лет назад
Hello can you please explain in details why we need the Pass Arguments to a Bash-Script ? please reply me as soon as possible. And Thanks for wonderful tutorials for shell scripting language
@surajkalyankar3350
@surajkalyankar3350 6 лет назад
Hi sir,you expalained all videos nicely but have one doubt that all these videos are enough for 2+ exp or not?
@akhilmunjolil9474
@akhilmunjolil9474 6 лет назад
Realy helpful
@shwetasingh-xj9lq
@shwetasingh-xj9lq 4 года назад
it helped me in my script - array input as stdin. Thankyou for sharing this.
@himanshusinghtomer2287
@himanshusinghtomer2287 4 года назад
Hey do u know about blue green deployment ...can u help me write a script for that
@himanshusinghtomer2287
@himanshusinghtomer2287 4 года назад
@@jesmmikababy yes
@himanshusinghtomer2287
@himanshusinghtomer2287 4 года назад
Need any help ?
@himanshusinghtomer2287
@himanshusinghtomer2287 4 года назад
@@jesmmikababy okk cool let's connect
@himanshusinghtomer2287
@himanshusinghtomer2287 4 года назад
@@jesmmikababy himanshu.tomer.1991@gmail.com
@consideration8881
@consideration8881 4 года назад
thank you!
@apporvaarya
@apporvaarya 5 лет назад
good tutorial :)
@tusharghude15
@tusharghude15 7 лет назад
good tutorials one request - please explain how array (or similar tool/program functionality) works in details before using them in examples tip for beginners: if ur scratching ur head wondering why shell didnt print actual values but only variable names when he used echo 'echo > $0 $1 $2 $3' its because shell doesnt expand variables in single quotes (but it does in double quotes - see prev examples)
@mingyan8081
@mingyan8081 6 лет назад
echo $1 $2 $3 "> echo $1, $2, $3" will display the values you pass into the bash script.
@yaminisagala
@yaminisagala 3 года назад
i was just scratching my head for this. your info helped!
@raghavendraganta4
@raghavendraganta4 2 года назад
thank you bro
@manuelconte2127
@manuelconte2127 2 года назад
you are good!
@renishdevani6217
@renishdevani6217 Год назад
Best explanation and it's helpful for the students like me whole series is outstanding thanks man ! and you also having nice voice .
@mamtachahal1277
@mamtachahal1277 4 года назад
I know its very late, but one thing, at the end when the cards to some other videos and your channel's appear it blocks almost all the screen. 8:25
@Cerlienkus
@Cerlienkus 6 лет назад
Hi First of all good tutorial. I've tried myself the examples in in this video but I've noticed a different behaviour. When assigning to a variable the array of input parameters like you do with args=("$@") it seems to refer to all parameters except the script name I've tried my script calling ./myscript.sh one two three when it reached the statement echo "Parameters from input: ${args[1]}, ${args[2]}" I expected it to print "one, two". Instead it printed "two, three" Modifing the statement like echo "Parameters from input: ${args[0]}, ${args[1]}" the result was what I expected Also, statement echo $@ seemed to print input parameters except script name. How do you explain this? Hallo and thanks from Italy
@confidential303
@confidential303 6 лет назад
The array index start at 0, args[0] args[1] args[2] are in your example one two three. args("$@") cannot parse the filename by default. If you still insist on getting the filename just use $0 $0 args[0] args[1] args[2]
@malwaredev33
@malwaredev33 Год назад
Nice video
@venuvenu9785
@venuvenu9785 4 года назад
is " " really required in passing values/arguments/messages in the echo statement ?
@hermitsf3
@hermitsf3 5 месяцев назад
No , some times
@ronaldmcsidy763
@ronaldmcsidy763 2 года назад
Need help from you man. It could save my job!! How do I create a shell script and run it in a remote system in-memory without actually creating the script file using ssh. I cannot use scp
@2454014
@2454014 7 лет назад
Make some apache videos later please too. Generically.
@dustybasement9062
@dustybasement9062 5 месяцев назад
Dude im broke af but i would definitely contribute if you started a gofundme for these kind of videos
@vaishnav4035
@vaishnav4035 6 лет назад
Sir. ..one doubt.. cd command is not working when it is included in the bash script.. How to solve this problem 🤔🤔
@masudkarim9022
@masudkarim9022 5 лет назад
use cd .. to back
@masudkarim9022
@masudkarim9022 5 лет назад
cd .. don't forget to give dot symbol
@guidopuccetti110
@guidopuccetti110 3 года назад
In the lecture number 2 you said that the variables could not start with numbers, but here you did. Did I miss something?
@athanasiospapazoglou7310
@athanasiospapazoglou7310 3 года назад
You cannot have numbers in your variable because the shell will misinterpret the variable into an argument If you remember $10val got interpreted as $1 (not 10val) .
@ussamabarakat4258
@ussamabarakat4258 4 года назад
is it called positional parameter ?!
@JoseGonzalez-yb7om
@JoseGonzalez-yb7om 7 лет назад
Cual es la diferencia entre ftp y samba Saludos desde centro América
@mikewilliams1035
@mikewilliams1035 3 года назад
no se la diferencia tal vez FILE TRANSFER PROTOCOL lo siento
@geniusworld7484
@geniusworld7484 2 года назад
sir can you please give us your source code it will more help us . to solving the problems
@shalvi5342
@shalvi5342 4 года назад
Why did you put '> echo $1 $2 S3' ? Even without that, it's displaying the result.
@UnknownSend3r
@UnknownSend3r 4 года назад
That's what I'm thinking, did you find out why he done that
@UnknownSend3r
@UnknownSend3r 4 года назад
Hes doing it to better illustrate where each variable is saved. It's for the benefit of the student.
@vaibhavvalandikar3913
@vaibhavvalandikar3913 4 года назад
Sir at 4:11 why is there a need to write $@ in double quotes
@ChaitanyaShar19
@ChaitanyaShar19 3 года назад
he is trying to parse those arguments when declaring in an array list
@prashantsrivastava3913
@prashantsrivastava3913 5 лет назад
please clarify what $? stands for?
@purushottamgupta4892
@purushottamgupta4892 5 лет назад
Shell variable
@ManishKumar-yv9ht
@ManishKumar-yv9ht Год назад
I learned when you don't want to delete a line , simply just comment # it
@stevenlee1726
@stevenlee1726 6 лет назад
My computer has 4GB Ram. First i try 0.5GB for Virtualbox, Lag. Then, 1GB, still lag. Eventually 1.5GB, Host and virtual run very smooth Yeah!
@Stszelec01
@Stszelec01 6 лет назад
you shoud try tiny core linux
@MegahToshi
@MegahToshi 5 лет назад
The command "Clear" is spelt CLAER in this tutorials ??????
@raw_wish
@raw_wish 5 лет назад
Even I noticed it, I don't know how it worked! :P
@amroz2611
@amroz2611 5 лет назад
echo "Enter names:" read name1 name2 name3 echo " Entered names : $name1 , $name2 , $name3 " Input - a b c Output - a, , Kindly tell where it went wrong
@muhammadsafiullah8428
@muhammadsafiullah8428 5 лет назад
I copied and pasted your code and it worked fine.
@amroz2611
@amroz2611 5 лет назад
@@muhammadsafiullah8428 Can you please tell on what linux environment (or distro) the code worked ( Assuming that the output was- a,b,c)
@muhammadsafiullah8428
@muhammadsafiullah8428 5 лет назад
@@amroz2611 Ubuntu
@nameshb1470
@nameshb1470 5 лет назад
what is an array? short answer.
@rt_onezer0215
@rt_onezer0215 5 лет назад
Think of it as a container that holds objects. For example it holds different fruits such as apples, oranges bananas in the variable fruits. When you want to 'take' a fruit from the container, you access it by writing fruits[0], which takes the very first fruit from the container. NOTE: arrays always start from the index 0, hence why I wrote fruits[0], not fruits[1]- that would be accessing the second fruit in the container
@boopeshkumarprabhakaran
@boopeshkumarprabhakaran Год назад
how to run this in windows
@markusscvilikovskis9051
@markusscvilikovskis9051 Год назад
WSL or virtualbox
@rupaligaikwad20aug
@rupaligaikwad20aug 2 года назад
Hi, what's your name
@victor-ioncislari2375
@victor-ioncislari2375 5 лет назад
finally, a Hindu who is worthy for youtube ;))))) just kidding. great nations are everywhere.
@bohemia6708
@bohemia6708 3 года назад
You speak english like an Indian, so I can understand...
@mauro_mirez
@mauro_mirez 6 лет назад
Hey mate, awesome videos but you need to work on some English pronunciation as it tends to confuse, and therefore, becomes distracting. After paying attention to some words here are a few examples of your mistakes: variables: you must put the accent in va, not in the a at ria. The accent goes on the first syllable from left to right. array: the accent goes at the last a from left to right, not in the first one. @: just say "at symbol" or simply "at"
@jonathanjohansson6011
@jonathanjohansson6011 6 лет назад
He is a programmer..not your English teacher dear Grammar Nazi ! ! !
@user-rp6xi4il5z
@user-rp6xi4il5z 6 лет назад
Mauricio Ramírez bro,i have watch many programming videos made by Indian teachers,i have been used to there horrible accent;just ignore it,the teacher is much more awesome than your professor ,isnt ?
@mohammadsalehi6151
@mohammadsalehi6151 5 лет назад
Ramirez, get your money back bro. If you take this class on Udemy they will charge you $20 per month. Here it is free, so appreciate it.
@vaibhavchauhan8832
@vaibhavchauhan8832 5 лет назад
and where does your perfect English took you in your life?
@asingh2507
@asingh2507 5 лет назад
Click video and on the top right you will see three dots. You click on it and choose caption in English auto generated.
@jalalshahini
@jalalshahini 4 года назад
This is an amazing tutorial for teachers to learn how not to teach.
@justawfulgamer7738
@justawfulgamer7738 4 года назад
this video was confusing AF for me
@amandeepgera4109
@amandeepgera4109 4 года назад
coudnt understand this lecture.....bad explaination
@Dhondupphuntsok
@Dhondupphuntsok Год назад
good basically ,quite slow ,,,,, lookalike's like untrained ...
@antuadhikari
@antuadhikari 2 месяца назад
It’s really helpful 🥹 thanks you so much ❤️❤️
Далее
Bash Scripting Tutorial for Beginners
47:57
Просмотров 401 тыс.
Become a shell wizard in ~12 mins
12:25
Просмотров 195 тыс.
BASH scripting will change your life
14:18
Просмотров 987 тыс.
How I’d learn ML in 2024 (if I could start over)
7:05