Bash Scripting - Variables, Arrays, If-Then-Else

  Рет қаралды 47,128

DistroTube

DistroTube

Күн бұрын

Пікірлер: 109
@wagnerrodrigues6440
@wagnerrodrigues6440 5 жыл бұрын
Thanks for the video, very nice introduction to scripting! I really enjoy you showing the mistakes and little of how you think while solving them.
@DistroTube
@DistroTube 5 жыл бұрын
Thanks, Wagner!
@user-gi2mn5yf5j
@user-gi2mn5yf5j 5 жыл бұрын
You had me at Dmenu scripting I am totally into that. So I used to script a lot to get the most out of my text based mud game without cheating. Since I quit playing games I have missed scripting a lot. I don't know much about bash scripts but this is a breath of fresh air :)
@arkansawdave7428
@arkansawdave7428 5 жыл бұрын
Haha. I've watched about 25 seconds of this and YES, it exactly what I've been wondering. I like using a terminal and have been doing it for years but I have no real idea how scripting works. Perfect. Thanks.
@med5032
@med5032 5 жыл бұрын
> /bin/ls -d.... you have an alias with ls. you can run unaliased ls with \ls like you would escape a space or quote. > & & and ; and && all behave differently; so, use them wisely. ``` false; echo "yes" # prints "yes" true; echo "yes" # prints "yes" false && echo "yes" # does not echo true && echo "yes" # prints "yes" ``` & does everything asynchronously. > ' (single quotes) " (double quotes) are the same. no, single quotes will not evaluate your variables. double quotes will. (I think there is something else that will be evaluated using double quotes.)
@ndanielamaha5618
@ndanielamaha5618 2 жыл бұрын
Thank you DT. I'm new to bash and I need to learn it for Bioinformatics and this has been a wonderful introduction to the world of bash.
@arminmatthes
@arminmatthes 3 жыл бұрын
Your reasoning for using the options variable was to avoid having to come in and change a bunch of stuff whenever the directories or files have changed, yet this is exactly what you'll have to do because of your if-statements whenever the number of directories is not equal to 6. A better way of doing this would be to simply check whether or not a subdirectory with the name of $choice exists in $myDir and then open emacs at that location: if [ -d "${myDir}${choice}" ]; then exec emacsclient -c "${myDir}${choice}" else echo "No such directory" fi
5 жыл бұрын
You are definitely not "on the safe side" by using #!/usr/bin/bash instead of the more normal #!/bin/bash. Also, if you write your scripts POSIX compliant, which you should, use #!/bin/sh. That's being on the safe side.
@davidh.4944
@davidh.4944 3 жыл бұрын
Umm, _why_ should you make your scripts posix compliant? If you have bash, use bash, and take advantage of all of its advanced features. That's what the shebang is there for-to tell the system which interpreter to use when executing the script. There's no need to hobble yourself with the limited syntax of posix unless your script needs to be completely portable across multiple, unknown platforms. I don't know why people always make such a fuss about posix compliance and portability, when most scripts are written to solve a specific task on a specific machine, with an environment the writer knows about. Besides, you will only very rarely find a linux system, at least, that doesn't have bash installed. And if you are the type of person who finds himself frequently porting scripts around, you're probably also the kind of person who knows what to do if it isn't. And finally, even posix scripts can't be safely run on unfamiliar hardware without at least a cursory check of the available commands and file paths.
@andrewa3216
@andrewa3216 2 жыл бұрын
Did you watch the video? He literally did a whereis bash to find out exactly where it is first. He never made it seem like that 100% would always work. What he DID say would always work was /usr/bin/env
@AnzanHoshinRoshi
@AnzanHoshinRoshi 5 жыл бұрын
Thank you, Derek. It's always good to see bourne again shell testifying.
@chreshcat
@chreshcat 2 жыл бұрын
Thanks Derek, your video prompted me do some self teaching (which I presume was the aim of the video). Thought I'd share the feedback so you keep your video's coming. Cheers
@JonDoe-gi5zf
@JonDoe-gi5zf Жыл бұрын
Just got my first Linux cert, your videos were really helpful. 🙏
@seraph_86
@seraph_86 Жыл бұрын
Thank you DT i added this to autostart nvidia-settings --assign CurrentMetaMode="nvidia-auto-select +0+0 {ForceFullCompositionPipeline=On}"
@ViniciusProvenzano
@ViniciusProvenzano 5 жыл бұрын
Hi, I see you are into Arcolinux. I love it, and I’d like to see more content on it from you. Great video!
@ishanagarwal475
@ishanagarwal475 5 жыл бұрын
Acrolinux is a themed archlinux with an installer it saves u some time in not learning how to write your own config ... It is not that different from arch whatever goes for arch goes for arcolinux too..
@ViniciusProvenzano
@ViniciusProvenzano 5 жыл бұрын
@@ishanagarwal475 You're right. I've already installed Arch, and created my configs. But Arcolinux is the easiest way to get Arch running with some sane configurations. I think that the approach to the problem can be different to achieve the same result. You can go with Arch and install what you need and keep all tidy and minimal, or you can go with Arco and just uninstall most of the stuff you will not use. I think it is interesting that I manages to work very well with both approaches, but when I tried to so a similar path with Manjaro, I just got crazy. By the way, you can install ArcolinuxD, and have a very functional bare minimum Arch installation, in under 10 minutes. From there you can configure as you wish... Take a look here: kzbin.info/www/bejne/fF6pcmiprLWcjpY
@joetheman74
@joetheman74 4 жыл бұрын
For GUI text editors Kate is fantastic. BTW every time I hear shebang I think of William Hung. How many people remember and know what I am talking about.
@anonpoliticallyincorrect9721
@anonpoliticallyincorrect9721 4 жыл бұрын
Thank you, I was looking for a video like this!
@andrewpalm2103
@andrewpalm2103 5 жыл бұрын
Good info, Derek. I'm going to look into using rofi in a similar fashion.
@__-wv1my
@__-wv1my 5 жыл бұрын
.fr ? Parlez-vous français ? Cool, je ne savais pas. Merci pour la video, c'est très instructif !
@alexandrosvangelatos9979
@alexandrosvangelatos9979 3 жыл бұрын
Great video, used it to launch of pdf files I have for label printing. Thanks
@sys7emH4cked
@sys7emH4cked Жыл бұрын
Very helpful tutorial thanks D.T for making this useful contents. 👉👍👈
@themagicrabbit1877
@themagicrabbit1877 5 жыл бұрын
Any text editor? Can I use Microsoft Notepad?
@DistroTube
@DistroTube 5 жыл бұрын
Yes, you can.
@themagicrabbit1877
@themagicrabbit1877 5 жыл бұрын
@@DistroTube YES!!! Now I just need to figure out how to get it installed on Arch...
@themagicrabbit1877
@themagicrabbit1877 5 жыл бұрын
@Farouk Mokhtari Oh really? I did not know that. The joke is on me now I suppose. I don't even use notepad at work anymore due to it's lack of syntax highlighting.
@popespalace823
@popespalace823 5 жыл бұрын
Yeah use wine haha 🍷
@themagicrabbit1877
@themagicrabbit1877 5 жыл бұрын
@Svein Are Karlsen Actually, Notepad got support for Unix line endings in May 2018. It's still one of the least impressive text editors around though.
@spidertube1000
@spidertube1000 5 жыл бұрын
Derek you're my hero
@90hijacked
@90hijacked 5 жыл бұрын
איזה יופי, אני לא לבד פה
@benpit5012
@benpit5012 2 жыл бұрын
Dd if= of=/dev & &( Ampersand) at the of a line gets command run in background so u dont have to wait for dd to finish Thanks for all your words of wisdom help advice guidance etc.
@sheikhshakilakhtar6844
@sheikhshakilakhtar6844 5 жыл бұрын
Hello, thanks for the video. Would you mind doing a tutorial on configuring xterm? I have come across quite a few on urxvt, but not anything useful on xterm.
@DistroTube
@DistroTube 5 жыл бұрын
The configuration for xterm is similar to urxvt: you use the .Xresources file.
@sippstea5453
@sippstea5453 5 жыл бұрын
Learnt something today.
@devon660
@devon660 5 жыл бұрын
Before you run your shell scripts always lint them with shellcheck! There are a lot of pitfalls when writing shell scripts.
@sch8836
@sch8836 5 жыл бұрын
Been meaning to learn bash scripting but was just too lazy. But now that DT has uploaded it, I will get to learn it.
@DaveSomething
@DaveSomething 5 жыл бұрын
I've /bin/bashing the keyboard! lame, I know... not as bad as shebang! sudo apt purge sudo
@toosafelol
@toosafelol 5 жыл бұрын
After that just use su and then reinstall sudo
@piotrarturklos
@piotrarturklos 5 жыл бұрын
This is awesome, very clear. And you've picked an example project which is a good one for bash, where calling terminal commands is really important to avoid cruft and boilerplate. If you can make another episode, a more technical one with quirks of bash syntax, that would be like a good next step and also very interesting to me personally.
@laarags
@laarags 2 жыл бұрын
Thanks for sharing 👍
@urugulu1656
@urugulu1656 5 жыл бұрын
im using shellscripts for finding and converting audiofiles around and then removing the source (find in all its glory together with ffmpeg in its respective glory is just to much for me to remember and execute on a day to day basis). btw i spotted csgo footage on your machine is there anything to expect
@DistroTube
@DistroTube 5 жыл бұрын
Old videos. I haven't played CSGO probably in a year.
@santoshgujar5237
@santoshgujar5237 2 жыл бұрын
Thank you, Sir
@bahathir_
@bahathir_ 5 жыл бұрын
In GNU Emacs GUI, we can resize the font with C-x C-+ #Increse font's size C-x C-- # Decrease font's size Thank you.
@loarto
@loarto 5 жыл бұрын
You can usually increase the font in the terminal. st f.ex. uses ctrl+shift+{page up, page down}. problem with using terminal, is that emacs don't control how text is displayed. The terminal does. GUI and terminal are very different.
@yiannifunataoldotcom
@yiannifunataoldotcom 3 жыл бұрын
Hey!! I d love to see how we could check if choice was in the list and if so just use choice to launch dired
@juanpmarinr
@juanpmarinr 5 жыл бұрын
What WM are you currently using ?
@DistroTube
@DistroTube 5 жыл бұрын
Xmonad in this video.
@stylianoslayranos6881
@stylianoslayranos6881 5 жыл бұрын
Thank you for uploading another quality video.
@DistroTube
@DistroTube 5 жыл бұрын
Thanks! :D
@maxpolaris99
@maxpolaris99 2 жыл бұрын
& is put in background, why do you want to start these programs in the background?
@kellingc
@kellingc 4 жыл бұрын
The & shovesd the comman into the background. So "sleep 3 &" creats a job in the background and 3 seconds later. If you use the jobs command, this will show all the background jobs that running.
@robertmarder126
@robertmarder126 5 жыл бұрын
Just FYI, for your shebang line, it's always better to not reference the path directly, so you don't run into the situation you showed here with /bin/bash verses /usr/bin/bash (or even /usr/local/bin/bash as is common on the BSD's) #!/usr/bin/env bash /usr/bin/env is so commonly used that no distro dares move it anywhere else. Of course, what would be even better, is to make your scripts POSIX compliant. Then you can just use #!/bin/sh without worrying what the particular shell is.
@md.imamulislam7
@md.imamulislam7 5 жыл бұрын
Someone running non-POSIX-compliant shell like FISH will run into problems if we leave the shebang line.
@robertmarder126
@robertmarder126 5 жыл бұрын
@@md.imamulislam7 every unix-like system I have ever seen uses a POSIX-compliant shell for /bin/sh regardless of what the user's personal shell is.
@SuperCape
@SuperCape 5 жыл бұрын
How did you get transparent background in Emacs? I WANT IT 😭
@RoKishDubbz
@RoKishDubbz 5 жыл бұрын
Install a compositor, such as compton. And tweak it up to add transparency
@kevinklement2621
@kevinklement2621 5 жыл бұрын
Great video, but I'm the annoying guy who has to point out that "ampersign" is not a word. The word you're looking for is "ampersand".
@DistroTube
@DistroTube 5 жыл бұрын
Hmm. If I add it as an entry to Urban Dictionary, does it become a real word? :D
@kevinklement2621
@kevinklement2621 5 жыл бұрын
@@DistroTube Yes, but you'll have to come up with a much dirtier meaning.
@kentjensen4504
@kentjensen4504 5 жыл бұрын
This is so cool.
@shwaybotx
@shwaybotx 3 жыл бұрын
Back in the day when you made this useful video you never looked at the camera. This is weird. We'd like you to look at us sometimes! I think your later videos improve on this point.
@stereo123
@stereo123 2 жыл бұрын
Did you create Bobby's world?
@danielyount9812
@danielyount9812 5 жыл бұрын
Good gist of bash shell scripting with Emacs. Still use the g(vim) here. Had never jumped into emacs. It does have some cool options.
@tlotlooepeng8721
@tlotlooepeng8721 3 ай бұрын
a single "&" means run this in the background while && is "and". so what happened is you ran the first 3 lines in the background then ran geany
@kentkou1872
@kentkou1872 5 жыл бұрын
I know you are demostrating the if else condition controls. But at the end 'if else' does not make sense as you are doing exactly the same thing with selected directory names. why not just do this: exec emacsclent -c ${myDir}${choice} Script will be much shoter and cleaner.
@DistroTube
@DistroTube 5 жыл бұрын
I hope to do another video continuing where I left off with this script, since I didn't really make the script do what I originally wanted. And yes, choice will be a part of that video if/when I get to it.
@artadams1
@artadams1 3 жыл бұрын
Friends don't let friends use EMACS
@elisium8242
@elisium8242 5 жыл бұрын
How i can run my script one time on startup? (I'm on debian stretch)
@DistroTube
@DistroTube 5 жыл бұрын
Will vary depending on what desktop or window manger you run. There is a way to autostart programs in every desktop. Google the solution for what you are running.
@harrytsang1501
@harrytsang1501 5 жыл бұрын
Sounds like you would like a systemd service. Search "Create A Custom Systemd Service" for more details. Once created, enable it to run on startup. If you want to interact with your script at some point, you can use a tmux session to house the process. e.g. ExecStart=tmux new-session -s SessionName ScriptFile ExecStop=tmux kill-session -t SessionName Then you can use `tmux attach -t SessionName` to interact. Once you are done simply press "Ctrl-B" followed by "D" to detach
@jeff-kj3pb
@jeff-kj3pb 5 жыл бұрын
you could add a line in your ~/.xinitrc file with the line: ./myscript.sh &
@DaveSomething
@DaveSomething 5 жыл бұрын
speaking of bash... I did write a nifty .bash_profile that gives me information about a system when I login via SSH. things like space on a particular drive, the temp of the cpu, heh I even added the weather in that area.
@DistroTube
@DistroTube 5 жыл бұрын
Nice!
@Broly_1
@Broly_1 5 жыл бұрын
I really want to learn but man it is not easy as it look.
@linuxterm7622
@linuxterm7622 5 жыл бұрын
Right when I was learning bash
@arcanelore168
@arcanelore168 Жыл бұрын
Easy!
@_yuri
@_yuri 5 жыл бұрын
henlo
@hademvids
@hademvids 4 жыл бұрын
Text editor? No, no, no, no, no... echo “~~~” >> .txt
@denisde4ev
@denisde4ev 4 жыл бұрын
no, no... cat >> .txt
@natemaia9237
@natemaia9237 5 жыл бұрын
you forgot 'fi'
@cam2291
@cam2291 5 жыл бұрын
TLDW: step 1: install gentoo
@ciatronic5904
@ciatronic5904 5 жыл бұрын
what does tldr mean? talk less draw more?
@cam2291
@cam2291 5 жыл бұрын
@@ciatronic5904 oops it's tldw fixed it
@linuxrant
@linuxrant 2 жыл бұрын
micro!
@Cyanwasserstoff
@Cyanwasserstoff 5 жыл бұрын
The coding feels similar, I am no expert so please excuse my question, but is it possible that the bash is using C++ or a similar programming language ?
@jeetadityachatterjee6995
@jeetadityachatterjee6995 4 жыл бұрын
Bash is written in c (like most gnu projects) there maybe some pass through
@davidh.4944
@davidh.4944 3 жыл бұрын
Bash syntax is bash syntax. But the underlying base decends from the original bourne shell and the posix standard, with a good number of other features "borrowed" from ksh, and zsh, and other sources. Cross-pollination is very common among scripting and programming languages, and you'll find that a lot of them have taken a hefty dose of inspiration from C-family syntax. Not really surprising, since so much of the underlying infrastructure is written in it.
@caremyok
@caremyok 5 жыл бұрын
mmmm
@scifregizmoguy
@scifregizmoguy 5 жыл бұрын
I love you're channel, DT, but this video was painful to watch. Maybe you should have planned a little better.
@RM-ff1lm
@RM-ff1lm 5 жыл бұрын
I disagree. I gained a lot of knowledge from this video.
@scifregizmoguy
@scifregizmoguy 5 жыл бұрын
@@RM-ff1lm It does have a lot of information. I'm referring to the delivery, and the many mistakes he made which could have been misleading for a noob. Misinformation is worse than lack of information. He didn't even know why his scripts were failing.
@RM-ff1lm
@RM-ff1lm 5 жыл бұрын
@@scifregizmoguy I'm sure he did most of that on purpose because he was showing how to correct the problems you run into when you create your own scripts. I wish I had this video when I first started scripting because I had no idea how to fix my mistakes.
@scifregizmoguy
@scifregizmoguy 5 жыл бұрын
@@RM-ff1lm Fair enough
@hoobsug
@hoobsug 5 жыл бұрын
shouldve stopped listing editors after mentioning geany. electron based editors must die
@pepeshopping
@pepeshopping 5 жыл бұрын
Wow... “Teaching” scripting and “not expecting that to happen”. What exactly did you expect from launching the command sleep to the background?? (Hint: It returns immediately!). Find a better teacher...
@BreakTheBeat852
@BreakTheBeat852 5 жыл бұрын
Damn dude chill out he’s just trying to teach us some useful stuff, everyone makes mistakes. I’m guessing you weren’t always as tech savvy as you are now
Shell Aliases Every Linux User Needs
29:03
DistroTube
Рет қаралды 38 М.
Players vs Pitch 🤯
00:26
LE FOOT EN VIDÉO
Рет қаралды 138 МЛН
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 7 МЛН
FOREVER BUNNY
00:14
Natan por Aí
Рет қаралды 31 МЛН
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
Chown, Chmod and Shell Aliases
22:07
DistroTube
Рет қаралды 13 М.
Become a bash scripting pro - full course
36:00
CODE IS EVERYTHING
Рет қаралды 68 М.
Learning Sed Is Beneficial For Linux Users
19:27
DistroTube
Рет қаралды 86 М.
BASH scripting will change your life
14:18
NetworkChuck
Рет қаралды 1 МЛН
Python Django Web Framework - Full Course for Beginners
3:45:41
freeCodeCamp.org
Рет қаралды 4,7 МЛН
Swift Programming Tutorial for Beginners (Full Tutorial)
3:22:45
CodeWithChris
Рет қаралды 7 МЛН
What Are Linux Users Putting In Their Config Files?
31:47
DistroTube
Рет қаралды 93 М.
Bash Scripting Full Course 3 Hours
3:08:04
linuxhint
Рет қаралды 1,2 МЛН
Let's Share Our Favorite Bash Aliases
16:28
DistroTube
Рет қаралды 32 М.
Players vs Pitch 🤯
00:26
LE FOOT EN VIDÉO
Рет қаралды 138 МЛН