Тёмный

Bash Scripting 3 -- Variables and Quoting 

tutoriaLinux
Подписаться 208 тыс.
Просмотров 61 тыс.
50% 1

How do variables work in Bash scripts? Wondering how to fix quoting errors in Bash? Bash Variables and Quoting -- two basic bash scripting concepts that you'll need to use the Bash shell effectively.
Full Bash Scripting Basics Playlist: • Bash Scripting
Step-by-step project-based Linux course for beginners: www.udemy.com/...
Free Linux Sysadmin Course Playlist: • The Linux Basics Cours...
DigitalOcean referral link: m.do.co/c/0380...
Patreon: / tutorialinux
Official Site & e-mail list: tutorialinux.com/
Twitter: / tutorialinux
Facebook: / tutorialinux
Podcast: kernelpanicpodc...

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

 

12 сен 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 42   
@samuraijack5919
@samuraijack5919 4 года назад
Bash Scripting 3 -- Variables and Quoting My Notes: What is this: $varname A variable - Why is it standard practice to put environment variables in all caps? They are outside the program (so you know not to mess with them) ie: $HOME (home directory) - What is this doing: myvar="This is so wonderful" Setting a variable (remember: no spaces) - What is this doing with the variable: echo "This is my ${some_number}th beer." Delimiting it (so that it can be inserted into a string - What is this doing with the information inside the ` ` characters: echo "there are `wc -l < /etc/group` lines in the /etc/shadow file" It is telling the shell that there is a command inside this string (and running it) - after, results are subbed in - Tell me if I missed anything. Be safe and have a great day.
@aungbobo89
@aungbobo89 6 лет назад
hi , i would like to say "Thanks!" for your very nice and informative videos. I've learnt new stuffs by watching "The Linux Basics Course".
@b00i00d
@b00i00d 4 года назад
Just as I'd been wondering, after all these years, whether there is any bloody use to backquotes! Beautiful!
@sullenbode283
@sullenbode283 4 года назад
Loved this video and the bash scripting playlist in general. One thing I wanted to point out for anyone else interested is that there is a newer syntax for using the output of a command in variables or with the echo command like Dave did in the video here - using $(command) will do the same thing as `command`, but I personally prefer the $() syntax just because it’s easier for me to reach those keys and is a bit easier to see.
@tutoriaLinux
@tutoriaLinux 4 года назад
Agree 100%, I should have been using that in the videos the whole time. Just an oversight from me; I've since retrained myself to use $() everywhere (except for string interpolation).
@justinwong4149
@justinwong4149 3 года назад
This was a succinct and informative video, thank you. Especially impressive since you were 9 beers deep.
@scottb4029
@scottb4029 2 года назад
Thanks younger pointing out the 'little things" like spaces, and their effect on the way the bash shell reads the program. I've read two books and watched 3 different series and that's the first time I have heard that tip.
@Bene9533
@Bene9533 9 лет назад
Hi, thank you for your nice and educational videos. I'm glad that there are people like you who give linux some love and encourage people to try it out. I just wanted to note that there is another way of command substitution which I'm sure you know of, but should have mentioned it in this video: $(command) According to tldp this has superseded the quoting due to some advanced features like nesting. I haven't watched all of your videos, so if you already did mention this feel free to yell at me ;) If not, you may want to include this in one of your upcoming videos. Keep up the good work. Greetings BaBene
@tutoriaLinux
@tutoriaLinux 9 лет назад
You're absolutely right; thanks for that. I'll try to mention that in an upcoming video.
@andrewstallard6927
@andrewstallard6927 5 лет назад
In addition, you forgot to change /etc/shadow to /etc/group in the message at around 8:30 . I commit these kind of gaffes more often than I like to admit as a teacher. Great series.
@vinyard1775
@vinyard1775 4 года назад
I was scratching my head earlier today when writing a bash oneliner to do a couple things. Of importance was being able to append the user defined input file. Didn't expect it to be as simple as >> ${varfile}_ Learn something new every day, thanks man!
@kikeonline
@kikeonline 8 лет назад
Wow! I just wrote and program that deletes all screenshots in my desktop and tells me how many files I deleted. echo "`rm -v ~/Desktop/Screen\ Shot*.png | WC -l` files were deleted"
@tutoriaLinux
@tutoriaLinux 8 лет назад
+kikeonline Don't know how I missed this when you posted it -- nice!
@jimkats1
@jimkats1 6 лет назад
I didn't even know about the command substitution in the echo. Great video :-)
@brentprox459
@brentprox459 8 лет назад
Your videos are the bomb man...
@amoslevin2895
@amoslevin2895 9 лет назад
cant wait for the next one ! actually what i mean is that i AM WAITING for the next one..... you rock.
@tutoriaLinux
@tutoriaLinux 9 лет назад
Done :-D -- next video is up!
@newwavex8665
@newwavex8665 7 лет назад
Thanks for leaving that cmatrix -abs on the screen, managed to find that screensaver.
@EDGHOLLOW9
@EDGHOLLOW9 5 лет назад
Thanks, I learned this the hard way 😂 should have watched your videos 😂
@holmberd
@holmberd 7 лет назад
Irrelevant to the point, but 69 lines in /etc/group not /etc/shadow.
@vokadlok
@vokadlok 5 лет назад
Hello, thank you for videos! Why do you prefer 'wc -l < file' to just 'wc -l file'?
@Justicewarrior795
@Justicewarrior795 2 года назад
group 69 is a new concept to me))
@Linux4Ever2011
@Linux4Ever2011 7 лет назад
Great explaining :)
@seankang8318
@seankang8318 5 лет назад
Thanks for the all the tutorials! By the way, is that a shell screensaver??
@gaithalbadarin6774
@gaithalbadarin6774 7 лет назад
Awesome..... Thanks.
@TapanJella
@TapanJella 4 года назад
Thank You Sir
@pr0jectSkyneT
@pr0jectSkyneT 4 года назад
how do you print out all the local variables you've created and how do you delete them?
@EmergencesDeSens
@EmergencesDeSens 8 лет назад
Hello, first of all thank you so much for these videos, I am more addicted to them than to Silicon Valley (the show...). Anyway, I have a question. When we create those variables for the exercices, where do they go? Are they stored in some files and if so how can I delete them when I am done ? Thanks a lot Pascale
@tutoriaLinux
@tutoriaLinux 8 лет назад
Hey Pascale, good question! Bash variables are stored in memory while your shell is running -- no files or anything. Once the shell instance (i.e. the specific running shell program that you're using) exits, those variables disappear (the memory where they are stored is re-used for other processes). If you open two shells, you can test this by setting a variable in one of them and trying to call that variable from the other one (it will only work in the shell where you set this variable). Things like .bashrc and .bash_profile files are used to set shell variables that should always be set at the beginning of every shell session. Hope that helps! Keep trying stuff and you'll get a good idea of how everything works.
@tutoriaLinux
@tutoriaLinux 8 лет назад
By the way, SIlicon Valley is awesome :-D
@EmergencesDeSens
@EmergencesDeSens 8 лет назад
Thank you for the explanation ... And yes, Silicon Valley is the best (geek) show ever! ;) - and thank you again for your videos...
@jimivie
@jimivie 4 года назад
why does "sudo wc -l
@Pizza0Taxi
@Pizza0Taxi 6 лет назад
isn't $(foo) a nicer way of `foo` ?
@tutoriaLinux
@tutoriaLinux 6 лет назад
Yes, it's better -- you can nest $() safely and it's generally easier to work with. See this for details: mywiki.wooledge.org/BashFAQ/082 -- sorry about that, I meant to do a 'bash style' video that shows you which bash features to prefer, but ran out of time on this series. Maybe I'll re-film this at some point and show only the good bash features :-D.
@AlDumbrava
@AlDumbrava 7 лет назад
"A fortuitous number comes up"
@limitless1692
@limitless1692 2 года назад
Who are we? Programmers! What position do we like? 69!
@Dyslexic_Neuron
@Dyslexic_Neuron 4 года назад
69
Далее
Bash Scripting 4 -- How Bash Scripts Work
12:00
Просмотров 64 тыс.
Using BASH Variables and Arguments
12:51
Просмотров 3,5 тыс.
OG Buda, Слава КПСС - LAZER SLAVA
01:58
Просмотров 59 тыс.
Bash vs ZSH vs Fish: What's the Difference?
13:32
Просмотров 179 тыс.
Linux Basics -- Scheduling Tasks with Cron
12:06
Просмотров 131 тыс.
Understanding Variables on the Linux Command-Line
18:01
Linux Shell Aliases: What You Need to Know
10:17
Просмотров 37 тыс.
this BASH script will make you a MILLIONAIRE
19:20
Просмотров 717 тыс.
Become a shell wizard in ~12 mins
12:25
Просмотров 247 тыс.