Тёмный

Shell Scripting Tutorial for Beginners 3 - Read User Input 

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

Read command - The read command allows you to prompt for input and store it in a variable. shell allows to prompt for user input.
Syntax:
read varname [more vars]
or
read -p "prompt" varname [more vars]
words entered by user are assigned to varname and “more vars”
last variable gets rest of input 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!

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

 

5 май 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 125   
@jpedithe2171
@jpedithe2171 Год назад
Bonjour Monsieur, merci de nous faire partager toutes ces astuces, c'est vraiment appréciable pour ceux qui débutent , j'apprends beaucoup en regardant vos vidéos Sarah
@JacobScott0000
@JacobScott0000 4 года назад
Thank so much for this series. I'm really enjoying following along. They're really great. Well done.
@yuyan9443
@yuyan9443 4 года назад
super efficient teaching. I learned and I solved my problem. Thank you so much
@apporvaarya
@apporvaarya 5 лет назад
this tutorial was brainstorming.. too much of learning in one go :)
@chetansingh7936
@chetansingh7936 3 года назад
You explained very nice man wish anyone had told me earlier about this channel 👍
@rovelpilueta9106
@rovelpilueta9106 6 месяцев назад
I'M AN EDUCATOR AND IM SO VERY THANKFUL BECAUSE OF YOU'RE TUTORIALS
@isabelarchibald5076
@isabelarchibald5076 6 лет назад
Thanks for the tutorial.
@basilgafoor1
@basilgafoor1 4 года назад
It was really a great user friendly tutorial. Enjoyed a lot. Keep making such videos in the future. We would love to see such videos coming up.
@UnknownSend3r
@UnknownSend3r 4 года назад
Do you know why the username and password got printed on the same line at 7:14 ?
@raj-nq8ke
@raj-nq8ke 3 года назад
@@UnknownSend3r he typed the password by keyboards and used -sp to flag or hide the password. But the line will read nothing and control will shift to 3rd line with changing line. I guess this is correct.
@UnknownSend3r
@UnknownSend3r 3 года назад
@@raj-nq8ke thanks bro.
@dtsleite
@dtsleite 5 лет назад
Great content!! I´ve been learn a lot! Thanks!
@raghavgupta1157
@raghavgupta1157 5 лет назад
10:56 : alias claer="clear" XD
@giorgostsilivis6771
@giorgostsilivis6771 5 лет назад
thats what i was thnking about lol xaaaxa
@MagicalCritical
@MagicalCritical 4 года назад
in vim: command! W write
@hirakmondal6174
@hirakmondal6174 4 года назад
How on earth it got execute?
@Jorgepex
@Jorgepex 3 года назад
@@hirakmondal6174 I guess he just pressed Ctrl + L which is usually the shurtcut for that command lol What a troll that man is
@bindassplay5114
@bindassplay5114 3 года назад
I am new in coding , what is alias
@aakarshitsrivastava6888
@aakarshitsrivastava6888 3 года назад
Thanks a lot these videos have really helped me out
@yel-hadd
@yel-hadd 5 лет назад
great work dude, thanks a lot
@shivprasadgurjar487
@shivprasadgurjar487 5 лет назад
great explanation, i am waiting for python scripting also
@ob9891
@ob9891 2 года назад
Thank you so much, this is enlightening
@Janith1980
@Janith1980 3 года назад
Would you be able to let me know whether more than one flags could be included in `read` command such as -p -a. Also is there an order for the flags. Thanks
@user-ug4ow1qq2h
@user-ug4ow1qq2h 4 года назад
You used echo both with and without quotation marks. Are these synonymous?
@harishbs3803
@harishbs3803 10 месяцев назад
using -sp and -a was very useful.
@moazelsawaf2000
@moazelsawaf2000 Год назад
Thank you so much ❤
@ShinAkuma
@ShinAkuma 3 года назад
How would you read a value that has spaces ?? I want a variable to hold a full sentence.
@weisheng1930
@weisheng1930 Год назад
Thank you!
@ashwinipatil2736
@ashwinipatil2736 5 лет назад
thanks very useful
@Andrzej3935
@Andrzej3935 4 месяца назад
Thanks a lot
@ahmetkarakartal9563
@ahmetkarakartal9563 Год назад
thank you so much
@BeHappyHealthy
@BeHappyHealthy 4 месяца назад
thanks a ton
@davelang68
@davelang68 5 лет назад
thank you
@webhunter2989
@webhunter2989 6 лет назад
claer works for me as well xD
@kamsalirohith-
@kamsalirohith- 5 лет назад
sir explain a shell script using command line arguements it starts with f or F it creates a file or if starts with d or D it creates a directory
@technicalresi5451
@technicalresi5451 5 месяцев назад
Very nice 😊❤
@buddhadebbairagi2022
@buddhadebbairagi2022 2 года назад
One thing that i noticed here is that the flagships are somekinda order-sensitive, means -ps didn't work, only -sp is producing the desired functionality.
@londoninseconds
@londoninseconds Год назад
I am looking for the script on which i will be able to monitor the user behavior in Linux domain.
@elyaserbenguno5464
@elyaserbenguno5464 Год назад
Sir, thank you very much for the great tutorial you offer to us. I want to ask, what is the difference between using and not using the quotation mark on the echo? e.g. [ echo enter your name ] and [ echo "enter your name" ], it gives the same output
@lovearora3153
@lovearora3153 4 года назад
Please make another video for another options of read command..
@prasannakumar4904
@prasannakumar4904 4 года назад
Thanks
@kushalgopee3033
@kushalgopee3033 5 лет назад
how do you pervent arrow keys as input
@lutfunchowdhury5711
@lutfunchowdhury5711 3 года назад
I'm having an issue here, whenever i type "$name1, $name2, $name3 " And writing . /hello.sh and enter the 3 name they are showing me 2names why?
@Ganeshay-996
@Ganeshay-996 2 года назад
Can i use in linux.. Virtual box this all command
@Akshatgajjar
@Akshatgajjar 5 лет назад
FOR WHICH PURPOSE WE USE read command in shell script? please answer
@sheejathomas7148
@sheejathomas7148 4 года назад
Hi, this is an excellent presentation. Could you pls let me know how to prevent system hang after installing Vm on a Windows machine? Because whenever I try running a code, my system hangs and acts weird
@yatharth2538
@yatharth2538 10 месяцев назад
How much RAM do you have?
@sinistergeek
@sinistergeek 5 лет назад
3:34 here code might show error show use this code **echo "Your name are : "$name1", "$name2", "name3""
@AshwinKabbinahalli
@AshwinKabbinahalli 2 года назад
how to count the number of inputs given to a read function?
@yogeshmahajan815
@yogeshmahajan815 Год назад
for me -a and -s is showing illegal option in my terminal , how to resolve this?
@stew9671
@stew9671 4 года назад
How does one clear the terminal after read -P in a while loop While [ -z $name ] Do Read -p "question" name Done But if I use clear nothing happens. The example code will not work it's in a function I just made $1 go into name
@chetan13579
@chetan13579 6 лет назад
What will happen if we assign three variable as name1, name 2 and name3 and giving only 2 inputs ... What will be assigned in name3 ? Garbage value or nothing ?
@niknikhil5873
@niknikhil5873 6 лет назад
You used alias for clear to claer?
@WhiteSparr0w
@WhiteSparr0w 6 лет назад
I think that might be the case.
@quicksaver503
@quicksaver503 3 года назад
When i use read command it show : not a valid identifier please how to solve it
@dear_prit
@dear_prit 6 лет назад
Hello Programming Knowledge, I am trying to use the read command on the Cygwin terminal but I am getting some error it says not a valid identifier 'name. Thanks.
@masudkarim9022
@masudkarim9022 5 лет назад
You can install a linux os using virtual machine
@madhulikamitra2227
@madhulikamitra2227 5 лет назад
If you are using Notepad++ to write your code, go to Edit ->EOL Conversion -> UNIX. Save your file and run, it should work. The line endings in windows causes this issue.
@sasha_444
@sasha_444 5 лет назад
use dos2unix command on the file as most probably you store your .sh files in windows system catalog
@cserpakbalazs6342
@cserpakbalazs6342 5 лет назад
@@madhulikamitra2227 Hey, I had the same issue and your advice helped a lot. Thanks!
@RajuRay-yl5lh
@RajuRay-yl5lh 4 года назад
@@madhulikamitra2227 smart very smart
@athilalthaf6222
@athilalthaf6222 4 года назад
Is the assigning of variable space sensitive?
@SonaliSingh-ou6qo
@SonaliSingh-ou6qo 4 года назад
yes
@Rahul-singh03
@Rahul-singh03 3 года назад
My shell file is not opeing by this command. /filename it's showing bad interepreter
@avinashbasetty
@avinashbasetty 5 лет назад
I tried with a single quote and it didn't work
@akshaymuragod8890
@akshaymuragod8890 Год назад
Thank You
@TheAceTroubleshooter
@TheAceTroubleshooter 6 лет назад
Getting error for echo "username is : $user/pass_var" Says echo: command not found... Whats up with that? Ive done everything exactly the same as you've typed it =/
@Raul111591
@Raul111591 5 лет назад
what extension did you install to write bash in vscode?
@ShinAkuma
@ShinAkuma 3 года назад
No extension is needed. VScode is just a text editor. If he wanted he would use the terminal directly from VScode as well.
@vikasmishra8559
@vikasmishra8559 5 лет назад
Illegal option -a ......why this error message comes everytime i execute the code
@sohelshaikh2697
@sohelshaikh2697 3 года назад
when i compile this it's show Illegal option for -s
@Ashishkumar-mw1gj
@Ashishkumar-mw1gj 3 года назад
Why $name inside semicolms?
@siddharthrajagopalan7326
@siddharthrajagopalan7326 5 лет назад
how do add -a and -p in one statement? read -ap does not seem to work
@grrrge2349
@grrrge2349 5 лет назад
Type in -a -p
@abhishektaneja3626
@abhishektaneja3626 4 года назад
why visual studio code and if not necessary can you tell me other editor i am curious
@tanmayrane858
@tanmayrane858 3 года назад
visual studio code is not necessary we can also use nano,vim,vi etc.
@pandeyabhishek8811
@pandeyabhishek8811 2 года назад
how to accept any command from users and according to that system will run that command like if user enter date command date will be print on screen and if user enter ls command all file list will display on screen that present in that folder?? how to write shell script for this ??
@PRamavarmaRaja
@PRamavarmaRaja 18 дней назад
Hi, you can do that simply by typing the command to the cli there is no need of a script or any other program to execute individual manually input commands. Shell scripting is usually used to automate certain recurring tasks, which is actually executing of many commands back to back. Hope this helps.
@Rock-rk9hh
@Rock-rk9hh 2 года назад
How to test if a variable is a number
@UnknownSend3r
@UnknownSend3r 4 года назад
7:23 why did the password and username appear on the same line ?
@aniketsingh4403
@aniketsingh4403 4 года назад
Same question..and it's solved by typing just echo👀
@thatbadguy2899
@thatbadguy2899 3 года назад
Even in C language you have to use for new line
@sritejayanamala5234
@sritejayanamala5234 3 года назад
y r u not using numbers for input??
@_EchoEnigma
@_EchoEnigma 3 года назад
-sp is giving as illegal option.
@SuprunAlexey
@SuprunAlexey 7 лет назад
Is shell relevant in 2017?
@SamSharifian
@SamSharifian 7 лет назад
Shell will be relevant while a Shell based OS is relevant!! And that is likely for the next few decades!
@VovaBlow
@VovaBlow 6 лет назад
Привет, Брат!
@AshwiniSingh27
@AshwiniSingh27 5 лет назад
clearly, you don't use linux
@dh00mketu
@dh00mketu 5 лет назад
@@AshwiniSingh27 even windows moving to shell.
@TalsonHacks
@TalsonHacks 3 года назад
It’s relevant in 2021
@tahirchaudhari
@tahirchaudhari 6 лет назад
nice tutorial,but u should explain all the symbols while typing the commands and running it b4r. eg. : $ etc
@drew1035
@drew1035 6 лет назад
watch the previous videos in the playlist..
@KaustubhAmle
@KaustubhAmle 7 лет назад
how can i give super user access to script ?? like let's say the script say's #! bin/bash sudo ping -l 6 xyz.com then the terminal promts for sudo password how can I respond to it from the shell script
@viviankris9939
@viviankris9939 3 года назад
Use command su rm - rf
@palashkhaire9656
@palashkhaire9656 6 лет назад
-s gives an error for illegal option used Im using VI editor to do so while iam running I got that error
@giteshkumar815
@giteshkumar815 5 лет назад
sir, try to give s before p, i.e read -sp _______
@newversion6098
@newversion6098 5 лет назад
@@giteshkumar815I use read -sp ___ but also get error The error is " read: Illegal option -s " What I do
@giteshkumar815
@giteshkumar815 5 лет назад
@@newversion6098 sir, then try to use another editor
@newversion6098
@newversion6098 5 лет назад
@@giteshkumar815 I am used terminal not editor bro
@thndesmondsaid
@thndesmondsaid 4 года назад
Does anyone else get stuck after the first read command? my script never executes the commands following it :?
@shellgenius
@shellgenius Год назад
Yes but I don't get any stuck or error Read syntax is used for take input from user through CLI
@veesamchaitanya9725
@veesamchaitanya9725 6 лет назад
you entered name1 , name2 ,name3 like this if i want to print 100 names at a time i have to give same like this name1 , name2,......soon .. ? or is there any other method
@ArunKumar.a7
@ArunKumar.a7 6 лет назад
you can type below commands here im creating a directory called 'names' to understand you better: mkdir names cd names/ touch name {1..99} ls Then see the output.
@prince43917
@prince43917 5 лет назад
Loop
@GamingBeast3
@GamingBeast3 7 лет назад
can you explain me this line of code please it's in vb.net Regex.Replace("ThisIsACamelCaseString", "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 ")
@_________________404
@_________________404 4 года назад
it's a regex expression. I hope u learned it since this was posted 3 years ago.
@surepallyadith1741
@surepallyadith1741 3 года назад
hey bro u confused me a lot ,i understood this after trying myself after many trials&errors .
@surepallyadith1741
@surepallyadith1741 3 года назад
but its intresting
@NikhilMoreBCSE
@NikhilMoreBCSE 3 года назад
1.5x should be fine
@user-ft8lx1qd4u
@user-ft8lx1qd4u 5 лет назад
why are you making the examples very complicated this is simple read command
@madhusreebera4484
@madhusreebera4484 3 года назад
claer is not working for me :-(
@FreebyrdFayelanx
@FreebyrdFayelanx 4 года назад
You went way too fast.
@farshadalaei-1512
@farshadalaei-1512 7 лет назад
you actually made this very difficult , its hard to understand this ...
@zinoholwerda3814
@zinoholwerda3814 7 лет назад
what is hard about it
@TheAceTroubleshooter
@TheAceTroubleshooter 6 лет назад
I disagree
@hozaifaowaisi1250
@hozaifaowaisi1250 6 лет назад
ii kinda agree
@Xialoh
@Xialoh 6 лет назад
I found it much easier than my professor's method of explaining it..
@WhiteSparr0w
@WhiteSparr0w 6 лет назад
what so hard to understand about this? O_o. In my opinion from the way he showed it anyone can understand it.