HomeОбразованиеRelated VideosMore From: theurbanpenguin

BASH scripting lesson 1 - create, execute and debug scripts

403 ratings | 86034 views
More videos like this online at http://www.theurbanpenguin.com In this mini series we will step you through your learning of BASH scripting. First of we look at where to create your scripts, naming convention and debugging scripts. All of this will use BASH on CentOS Linux but it is bash we are looking at not the distribution of Linux.
Html code for embedding videos on your blog
Text Comments (49)
Mark Konagai (1 year ago)
Is there any ways we can create Automation with bash? #blkid /dev/sdb1: LABEL="/disk1" UUID="60511bb1-efe1-4d30-b354-dcedd611e0f2" TYPE="ext4" Editing nano /etc/fstab UUID=60511bb1-efe1-4d30-b354-dcedd611e0f2 /disk1 ext4 defaults 1 2
Drake Johnson (2 years ago)
I don't know if you still look at these comments, but I had a few questions. First, is there a way to put if statements on one line? Second, why do you use "vi" instead of "nano" for text editing? I saw someone else use nano and a different person use vi. Is there somereason I should use vi over nano?
Drake Johnson (2 years ago)
+theurbanpenguin Thanks a lot. But by if statements on one line I meant could you do: if [[ $USER = "$USER"]] then echo "Your username for this computer is $USER." fi Instead of: if [[$USER = "$USER"]] then echo "Your username for this computer is $USER." fi
theurbanpenguin (2 years ago)
+Drake Johnson Sure: cd /etc ; ls This will first change to the /etc directory and then list it. There is no conditional logic here. In other words the 2nd command will always try to tun even if the first command fails cd /etc && ls Here the listing with ls only runs cif the first command succeds. So we know we are listing the /etc directory cd /test || mkdir test In this last example the second command only runs if the first command fails. In this case we create the directory if it does not already exist. All of these examples can include more than two commands. In the long run you can do more with vi or vim than you can with nano. Nano is great wheile you are learning but try vi as well
paasaa Nepali (2 years ago)
where did you get that if section from
stablizershock (2 years ago)
I want to execute command in current folder without defining patch how to do it>?
stablizershock (2 years ago)
+theurbanpenguin I made sh file named as "install.sh" and i use "sh install.sh to execute but I want my customers to just open the file and command run as intended so should I use "./install.sh" command?
theurbanpenguin (2 years ago)
+stablizershock ./<filename> or bash <filename>
DJ Ree Ree (2 years ago)
Relax, Kris. This is a learning environment for us all. Its not stupid about the comment i made as mary clo. I am at work and we have virtual box on our machines, we do technical support and you tube videos play extremely lower for us than that of windows. i was only commenting from my personal experience. No need to be insulting.
Brian McGrady (2 years ago)
when I echo $PATH I dont have a /home/bri/bin , any isea why?
theurbanpenguin (2 years ago)
+Brian Mcgrady you can add it to your path variable PATH="$PATH:$HOME/bin"
TraceguyRune (2 years ago)
2:10 Thank you . Now I can get my scripts to execute without "bash"
Albert Rama (2 years ago)
hello! after making the file executable I try to go back in /home/myname and execute bash01.sh but it tells me "bash01.sh: command not found". can anybody help? thanks
TraceguyRune (2 years ago)
+Albert Rama make sure its in one of the $PATH directories try this: mv bash01.sh $HOME/bin/
Albert Rama (2 years ago)
+theurbanpenguin thanks a lot
theurbanpenguin (2 years ago)
Go to the diectory where the script is a.n run it with ./scriptname
S4nj1 (3 years ago)
best shell scripting courses i've found on the entire youtube ! Can you please put them on a playlist so I can download them easily ?
S4nj1 (3 years ago)
+jackmatt47 i'm dumb gonna create it myself :P
Josh Oduyoye (3 years ago)
SO when you set USER to andrew... are assigning andrew to the user or are you using typing andrew when you execute it?
Jaime Santana (2 years ago)
+Josh Oduyoye That's an environment variable that gets its value upon login.
lovey731 (3 years ago)
This may be a stupid question to ask, but. Is this Windows, or is that just a design?
TraceguyRune (2 years ago)
+Totally Anonymous putty or alphacom
Totally Anonymous (2 years ago)
+TraceguyRune its prob putty
TraceguyRune (2 years ago)
He seems to being using a Windows SSH program to access a linux machine
Totally Anonymous (3 years ago)
+lovey731 Bash scripting is very orientated with unix and unix like operating systems...
lovey731 (3 years ago)
+theurbanpenguin aka It's running on Linux?
md abid (3 years ago)
Well video,,good for basic concept :)
kornsnap (3 years ago)
Thanks for the  video very however where do you define what the variable USER is in the script?
TraceguyRune (2 years ago)
+kornsnap $USER is a constant and a global. It's defined by the system
theurbanpenguin (3 years ago)
The variable $USER is set during the login and is part of your environment. As such you so not need to set the USER variable
M-sTer Moh (3 years ago)
thanks for this video it's very informative
Christopher Tucker (3 years ago)
The colors inside vim (or vi) are difficult to read. Change colors or at least disable the colors option.
greg shubert (3 years ago)
~bin isn't in my $PATH
brett sullivan (3 years ago)
can you help me finish my new android game? im getting tons of coding [email protected]!!!!!!!!! 1-512-545-3596  #letthegamingrevolutioncommence!
igotdembombs (4 years ago)
9:47 "We're testing to see if Andrew does not equal Andrew, and of COURSE Andrew does not equal Andrew"
Kevin Thomas (4 years ago)
Great introduction to bash Andrew.
Qasim Butt (4 years ago)
Lousy !!!!
Barack Lasagna (4 years ago)
that's sorta annoying how it's not == compared to most languages when checking
TraceguyRune (2 years ago)
+Barack Lasagna Actually, its about half and half. Half the languages out there don't require "=="
Brandan09997 (4 years ago)
I was thinking the same thing, also its [[]] for strings and (()) for ints is also annoying. 
aneesh reddy (4 years ago)
too gud nice explanation...
DullcetD (4 years ago)
Great stuff TUP, keep it up.
theurbanpenguin (4 years ago)
Nu, but speak a little. I have friends in Cluj and we visit at least every year
theurbanpenguin (4 years ago)
Nu, but speak a little. I have friends in Cluj and we visit at least every year
Koczewnik nawsegda (4 years ago)
You are romanian?
DoodahGurl (5 years ago)
Great video. Very informative! Thanks for uploading.
movw wvom (5 years ago)
Joe Chang (5 years ago)
Thank you !

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.