Тёмный
No video :(

212 Bash Scripting Examples 

linuxhint
Подписаться 54 тыс.
Просмотров 130 тыс.
50% 1

Liked this course and looking for more?
Please visit our refreshed and improved 4-hr Bash Boot Camp Course here:
linux-hint.tea...
**(TIMELINE - 1)**
Simple Hello World Script 00:00:35
Echo Command Without Newlines 00:04:20
String Concatenation With Echo 00:06:13
String Continuation Character 00:07:40
Echo with Tab Characters 00:09:12
Echo with Newline Characters 00:11:12
Echo with -x to Display All Commands 00:12:30
Printing Strings That Contain Single Quotes 00:14:46
Printing Strings That Contain Double Quotes 00:16:00
Write to a File from Inside A Script 00:18:07
Overwrite to a File from Inside A Script 00:20:04
Append to File Inside Script 00:21:41
Single Line Comments 00:23:40
Comments From Middle of Line 00:25:45
Multi Line Comments Using Heredocs 00:27:56
Simple Variable Usage 00:30:16
Multi Word Variables Combinations with Quotes 00:32:27
HOME variable 00:35:28
USER variable 00:38:16
HOSTNAME variable 00:39:24
Echo $HOME with Escape to Avoid Expansion 00:40:16
Writing to file in HOME Directory Using HOME Environment Variable 00:41:34
Simple Touch Command 00:44:47
Create a Symbol Link, Write To Linked File, Cat file 00:46:57
Chmod Command, Make Executable 00:50:40
Chmod Command, Make Not-Writable, Try to Write to it 00:53:29
Chown File To Different User, Run ls before, after 00:56:44
Underscore Variable, Touch File, Use Underscore Variable to Append to It 00:59:59
Let Command Arithmetic 01:03:42
4 Basic Operators, Add, Subtract, Multiply, Divide 01:05:13
Increment a variable 3 times with Increment Operator 01:07:56
Decrement a variable 3 times with Decrement Operator 01:10:34
Echo Number Modulus Second Number 01:12:36
Echo Number to Exponent of Second Number 01:14:50
Expr Command for Math 01:16:17
Double Parenthesis for Math 01:19:14
Double Parenthesis with Dollar Operator Assign to Variable 01:21:40
Multiplication has Precedence Over Addition Regardless of Order 01:23:43
Combine Two Strings In One Line With Variables 01:25:49
Combine Three Strings In One Line With Variables 01:29:09
Plus Equal Operator Combine Strings 01:31:24
Create Multi-Line String Variable with HEREDOC 01:34:38
Cat Multi-Line HEREDOC Text 01:37:04
If Conditional Statement 01:39:43
Logical And in Conditional Statement 01:43:00
Logical Or in Conditional Statement 01:46:53
If Elif Else Conditional Statement 01:51:29
Nesting If Conditions 01:58:28
Equal vs Double Equal Operator 02:01:36
Test Not Equal Strings 02:05:03
Test Two Strings Before or After alphabetically 2:06:33
Test String is Null 02:08:07
Test String is Not-Null 02:09:30
Test Numerical Comparisons Greater then, Less then 02:10:39
Test Numerical Compare Greater Then Or Equal, Less Than Or Equal 02:12:58
Test Compare Numbers Are Equal 02:15:02
Test Compare Numbers Are Not-equal 02:19:16
Test File Exists 02:19:15
Test File Is Not Zero Size 02:21:10
Test File Is A Directory 02:22:43
File Is A Symbolic Link 02:24:22
Test File Has Read Permission 02:26:18
Test File Has Write Permission 02:27:35
Test File Has Execute Permission 2:28:57
#bash #bashscripting

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

 

5 сен 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 59   
@linuxhint
@linuxhint 3 года назад
Liked this course and looking for more? Please visit our refreshed and improved 4-hr Bash Boot Camp Course here: linux-hint.teachable.com/p/4-hour-bash-boot-camp-by-linuxhint-com
@linuxhint
@linuxhint 3 года назад
*** TIMELINE-2 *** # Case Conditional Statement With Numbers 2:31:24 # Case Conditional Statement With Strings 02:34:02 # Case Conditional Statement With Wildcards 02:36:11 # Execute a Command With Backticks 02:38:13 # Execute a Command in a Dollar Parenthesis Variable 02:40:06 # Execute a Command and Capture STDOUT 2:42:00 # Execute a Command And Capture STDERR 2:43:40 # Execute a Command And Capture Return Code 02:44:49 # Bash Exec Command Hello World 02:46:20 # Eval Command 02:47:55 # For Loop List of Values 02:49:06 # For Loop on Range of Numbers 02:49:57 # For Loop Output of Command 02:50:26 # For Loop Files in Directory 02:51:26 # For Loop with Conditional Break 02:52:12 # For Loop with Conditional Continue 02:53:05 # While Loop With Integer Counter 02:53:41 # Until Loop Based on File Size 02:54:34 # Create an Array Variable Access by Index 02:55:21 # Create an Associative Array Variable Access by Index 02:55:52 # Accessing Array Members with Loop 02:56:36 # Time a Command 02:57:16 # Print Date 02:57:43 # Print Date With Format 02:58:19 # Print Seconds Elapsed for Block of Code 02:58:57 # Read Text From File, Print to Screen 02:59:27 # Read Text From File, If Condition Print to Screen 03:00:00 # Basic Read Command 03:00:44 # Read Command Into Array 03:01:16 # Read Command with Delimiter 03:02:08 # Read Command with Timeout 03:02:38 # Menu Option with Select Command 03:03:07 # Menu Option With Select Command From Array Variable 03:04:03 # Split String By Space 03:05:05 # Split String By Custom Delimiter 03:05:32 # Split String into Array Variable 03:06:04 # Split String by Multi-Byte Delimiter 03:06:35 # Parse Command Line Options with Position 03:07:33 # Parse Command Line Options With Shift Command 03:08:29 # Parse Command Line Using GetOpt 03:08:43 # Read Password from Stdin, Without Printing it 03:09:26 # Pipe Command Example 03:09:56 # Cat Pipe Word Count Example 03:10:36 # echo to bc Command for Math Expression Simple 3:11:46 # echo to bc Command for Math Expression More Complex 03:12:14 # Function Prints Common Text, Call Multiple Times 03:12:40 # Function Returns a String 03:13:10 # Function Takes Params, Returns Sum 03:13:56 # Tput Command to Print String 03:14:28 # Tput Command to Print Number 03:14:50 # Tput to Clear Terminal 03:15:35 # Tput to Print Attributes of Terminal Simple 03:15:52 # Tput to Print Attributes of Terminal More Complex 03:16:13 # Assign String Variable with Declare 03:16:36 # Check If Variable Created with Declare 03:16:55 # n Option for Declare to Nameref Alias 03:17:37 # Forcing Variable to Integer with Declare 03:18:14 # Forcing Case with Declare 03:18:45 # Readonly Variables with Declare 03:19:08 # Indexed Arrays with Declare 03:19:44 # Associative Arrays with Declare 03:20:12 # Define a Function if Not Already Defined Using Declare # Automatically Answer Question with yes Command 03:20:36 # Use And Operator to Run Second Command Only if First Succeeds 03:21:03 # Use Or Operator to Run Second Command Only if First Fails 03:21:58 # xargs to operate on all files in directory 03:22:40 # Wait For Another Command to Complete 03:23:10 # Combine Kill and Wait Commands 03:23:57 # Star Wildcard on File Selection 03:24:27 # Question Mark Wildcard on File Selection 03:25:17 # Square Bracket on File Selection 03:25:45 # Parenthesis and Pipe for File Selection Options 03:26:12 # Brace Expansion Comma Seperated List 03:27:01 # Brace Expansion Range 03:27:26 # Brace Expansion with Preamble 03:27:51 # Operating on List of Files with Brace Expansion 03:28:11 # Reference Home Directory with Tilde 03:28:40 # Parameter Expansion for Printing Constant or Variable if Unset 03:28:59 # Substring Expansion for Printing Part of String 03:29:25 # Parameter Expansion for Assigning Constant to Variable if Unset 03:29:55 # Check If File Executable, Set If Not 03:30:22 # Check If File Is Owned By User, Set If Not 03:31:18 # wc To Count Lines In A File 03:31:59 # wc to Count Characters in a File 03:32:38 # Head Command With Default Args 03:33:05 # Head Command to Print First 100 Lines 03:33:32 # Tail Command With Default Args 03:33:57 # Tail Command to Print Last 100 Lines 03:34:15 # Find Command to Locate Matching Pattern Files 03:34:33 # Find Command to Locate Files Based on Date 03:35:44 # cut Command to Parse Delimited Columns of Data 03:36:21 # grep Command to Search for Pattern 03:37:14 # grep Command to Search for Lack of Pattern 03:37:38 # grep Command to Search for Case Insensitve Pattern 03:38:03 # grep Command with Wild Cards 03:38:34 # grep Command to Search All Files in Directory Recursive 03:39:01 # grep Command to Search for File in a Directory Recursively 03:39:34 # awk Split On Whitespace 03:40:27 # awk Print Last Field in Each Line 03:41:07 # awk Print Only Match of Regex 03:42:00 # awk With If Else Condition 03:42:23 # awk With Ternary Operator 03:43:05 # sed To Replace Matching Text 03:43:38 # sed To Replace Second Instance of Matching Text on Line 03:44:06 # sed to Delete Specific Lines 03:44:39 # sed to Add a Line Before Matched Line 03:45:04 # sed to Add a Line After Matched Line 03:45:41 # Sort Data in File with sort Command 03:46:02 # Sort Data Ignore Case 03:46:29 # Sort Data numerically 03:46:58 # Print Unique Data with uniq Command 03:47:31 # Count Unique Lines in File with Sort, Uniq, and wc 03:48:22 # Convert Data to Uppercase with tr 03:50:15 # Convert Data to Lowercase with tr 03:52:06 # Create a tar File 03:53:44 # Create a Zipped Tar File 03:55:58 # Unzip a Compressed Tar File 03:57:14 # Parse JSON File with jq 03:59:01 # Print Specific Field in JSON with jq 04:01:49 # Print Cpu Info With Pseudo Filesystem 04:04:34 # Print Mem Info With Psuedo Filesystem 04:07:01 # Print Mounts With Psuedo Filesystem 04:08:10 # Print Network Stats With Psuedo Filesystem 04:09:45 # Print Disk Usage with du 04:12:10 # Print Disk Usage Human Readable with du 04:15:04 # Create File of Specified Size with dd 04:17:07 # Time Disk Writing with dd and time 04:19:22 # Send a Mail with mail Program 04:20:35 # Send a Mail with mail Program Change Subject 04:25:39 # Send a Mail with mail Program to Multiple Recipients 04:27:08 # Send a Mail with mail Program to CC and BCC list 04:29:00 # Print Mounts Usage with df 04:30:40 # Send a Mail with mail Program with Encoded Attachment 04:32:36 # Download Webpage with Curl 04:36:22 # Post to HTTP with Curl 04:39:31 # Put Command in Background 04:41:02 # Resume Command From Background 04:42:05 # Execute Last Command Again with Bang Bang 04:42:58 # tee Command to Print to File and Screen 04:43:57
@austinlawan3289
@austinlawan3289 8 месяцев назад
Thank you so much for this tutorial. I have been scared of bash scripting up until i found this tutorial. Your delivery is topnotch. Thank you!
@calgarygaoshan
@calgarygaoshan 3 года назад
Great video! 02:04:36 --> ‘=’ operator is used to compare the equality of two string values, not type comparison. So when compare two strings, there is no difference between using '=' and '=='
@saikumarravula
@saikumarravula Год назад
I was confused with this example. Thanks for your comment.
@voyagervishu4445
@voyagervishu4445 3 года назад
Very much appreciated mann...thanks a lottt...was searching all over internet for proper exercises like these...buddy pls do lot more tutorials in bash like these
@vinayak186f3
@vinayak186f3 3 года назад
My OS lab classes are starting this week ,Lucky to find this GOLD ! Thanks a ton sir 😄
@rishavsinha5402
@rishavsinha5402 3 года назад
I was searching for shell scripting questions for practice...only you have discussed the basics of shell scripting and that too in detail
@charlesklein7232
@charlesklein7232 3 года назад
FOUND ANSWER! it does in fact WORK! im using "alias" to run it! NOT! [./] like you need to! thats my problem here. this is very educational! need to see how to modify my alias!
@wesg01
@wesg01 3 года назад
This is one of the best tech youtube videos I have ever seen. Sincerely thank you!
@alextantos658
@alextantos658 3 года назад
great tutorial! Congrats! I use the shell for my classes and your course is a great resource not only for learning but for teaching as well. PS: By the way, you course has been an inspiration to me and I also created 3 short videos on using the shell for text processing on my channel. You are more than welcome to take a look at them. Thanks again for your effort and the nice teaching style!
@MillionaireBull
@MillionaireBull 3 года назад
🔥🔥🔥Awesome🔥🔥🔥 Please upload more videos related to bash scripting 🔥🔥🔥
@marklamarr3576
@marklamarr3576 3 года назад
Thank you so much for this upload. I'm learning and practising so much!!
@ashutoshsahoo5479
@ashutoshsahoo5479 3 года назад
Beautifully explained..
@stefosters
@stefosters Год назад
Great Video. Thank you kindly 👍
@charlesklein7232
@charlesklein7232 3 года назад
at approximately "9:09" it works! however thier is an ERROR that can occur! after backslash if you use a comment it will print the comment despite the FACT that it was highlighted in "blue" which implies it worked but it dont! and it will jam on next line! you cannot comment after backslash in script. obviously the backslash SEEs the comment because its a backslash! despite the fact that implies it wont by the script!
@maryamii0414
@maryamii0414 Год назад
Outstanding tutorial, thank you so much :)
@joselet12345
@joselet12345 3 года назад
Basics covered in detail
@machman23
@machman23 2 года назад
A cool collection of examples ThanX
@josephmusembi4391
@josephmusembi4391 Год назад
2:38:50, not a backtick (`) but a back slash (\)
@ojaslayaskar1091
@ojaslayaskar1091 Год назад
Great Tutorial ❤
@jsteins
@jsteins 2 года назад
Item #72 Return code, is easier to just say MYVAR=$? to save numeric code in MYVAR for use later, when deciding how to respond to errors. (instead of using a file to hold one nbr) You should also look into setting up err "trap()" functions, to help control shell script behavior, when an error occurs. A return code of ZERO means OK, and No Error, while other return values mean different types of status+error codes, depending on the program. Shell script "if" statements consider a return of Zero to be success/TRUE, which means that shell code is one of the few places where Zero == True, and Non=Zero (1,2,6,etc) is false. thus you can code: if grep "search string" datafile.txt ; then command1; cmd2; else cmd3; cmd4; fi so that grep searches a file, and two commands run if found, two others if missing Another shorthand for quick one-line "if" conditional is: grep "find string" datafile.txt && cmd1 ; cmd2 ## run these only if found grep "find string" datafile.txt || cmd3 ## run this only if NOT found
@TheDiuf
@TheDiuf 2 года назад
hope u got the point
@patriotlightning7791
@patriotlightning7791 3 года назад
Haven't seen it but liked it already!
@jsteins
@jsteins 2 года назад
Items #68 (Back-ticks) to #74 are wrong... at 2:38 (\) back-SLASH is NOT the same as (`) back-TIC char. Example: to replace item #68 VAR="`ls -l /etc | grep '-r..r..r' ` " #== Get list of all readable files from /etc, skip dirs, + Catch in VAR The back-TIC has been used since 1975 with Bourne(sh), Korn(ksh), and bash shells to execute a command line as chld-process, and catch/capture stdout from that command into a VARiable. This (`) back-TIC bourne-shell syntax is now considered "old" and more difficult to read, so within ksh and bash scripts it has been replaced with $(command line) syntax for 20 years, but runs the same. The `cmd line` syntax is still supported, just so 30yr old scripts using old syntax are not broken.
@gomo5628
@gomo5628 3 месяца назад
How can I retrieve data from Sq;l and then write it to file without erasing the file content that was already there?
@glendubie
@glendubie 2 года назад
Great tutorial thanks 😊
@iwanabemw2
@iwanabemw2 Год назад
Great vid wow!
@debayannew5083
@debayannew5083 Год назад
Example 28. What is the significance of Underscore variable over variable. TIA
@luisa1551
@luisa1551 2 года назад
Unix based systems do not need extensions in the name of the file to know what kind of file it is. That is only in Windows OS. The sh-bang in the script tells the system the program needed for running the program.
@MASiTech
@MASiTech 2 года назад
Hi Buddy, you know how much i looked for such a Tutorial, Can you please make such video for Python language. Im a IT Administor and try a lot to learn different Programing Languge and all the time i gave up. now looking for learning python with a Examples from scratch for Newbies. Thanks in Advance.
@ramamt6350
@ramamt6350 2 года назад
Very very tq............
@ashish14Pradhan
@ashish14Pradhan 2 года назад
The video is great but I Found one thing that was problem for me as their is no multiline comments in bash and at 30:07 the instruction for that is for something else I guess. Just giving a feedback.
@hemantjain9850
@hemantjain9850 3 года назад
any document or article link where I can read it offline?
@jsteins
@jsteins 2 года назад
Item #71 redirecting STDERR 2:44:00 does not work the way shown. Changing dest file name to stderr.out is still only catching stdout. (Note error message still comes to screen) Also: output with "hello" does not match script code shown in video moments earlier. Unix considers stderr to be file descriptor #2, and stdout is #1, stdin is #0 typing: command >2 errfile.txt > norm.txt sends any error message to errfile.txt, and at the same time sends normal stdout to norm.txt You can also use VAR=$(command >2 errs) with stdout in VAR, but send errors to file.
@hatdiadago-hk3ll
@hatdiadago-hk3ll Год назад
is bash consider as a programming language?
@simpletongeek
@simpletongeek 3 года назад
Saved. I could have used this last 2 weeks. Using self made typing tutor to practice, I achieved 100 WPM corrected. Would you believe it was done using bash? I didn't think it was possible! I modeled the program based on 10fastfingers, which unfortunately got buggy when I did a phone update.
@aditiupadhya5875
@aditiupadhya5875 3 года назад
thankyou so much
@pldvs
@pldvs 3 года назад
Saved
@kalikali5826
@kalikali5826 2 года назад
30.30 multi line comment is not correctly done what you done is not correct you do over write not comment to make them disappear on the execution
@good123g
@good123g 3 года назад
3:13:48 does not work for me :first.sh: line 4: retstr: command not found
@yurilsaps
@yurilsaps Год назад
For those who use not 'bash', but 'zsh', as o MacOS, the default redirect will not create a file (echo "Hello" > foo.txt) if foo.txt doesn't exists... the solutions is " >| " (echo "Hello" >| foo.txt)
@nadiabahar3110
@nadiabahar3110 2 года назад
how can i use curl for login????
@charlesklein7232
@charlesklein7232 3 года назад
at 14:32 DONT WORK! many of your examples threw your videos dont work. it runs but does not give details of operations. in some cases they just dont work. im using Ubuntu 16.04 and i think your using 20 but i dont think that should matter. were did you get the "-x" for bash would like see the details of it.
@mihajlodjokic596
@mihajlodjokic596 Год назад
Starting from the third hour, this tutorial becomes unfollowable
@pamkaur7874
@pamkaur7874 3 года назад
can we contact you directly...
@linuxhint
@linuxhint 3 года назад
talha@linuxhint.com
@pamkaur7874
@pamkaur7874 3 года назад
@@linuxhint ok thank
@pamkaur7874
@pamkaur7874 3 года назад
@@linuxhint I sent you email,please check it
@furqanalihunzai
@furqanalihunzai 2 года назад
in starting you were doing best but after 02hours 50 i guess it was worse. not recommended to watch after this
@midmanphilippines
@midmanphilippines 2 года назад
Grep
@amysworld5521
@amysworld5521 Год назад
46:00
@yusufaksoy3693
@yusufaksoy3693 Год назад
4 video
@fohsap7859
@fohsap7859 Год назад
Don't capitalize the variables you define.
@HoneyBadgerz
@HoneyBadgerz 3 года назад
i'm just starting with linux i think dont need to look any further
@AnthonyP2A
@AnthonyP2A 2 года назад
WHAT?
@DanCanning
@DanCanning 3 года назад
I could not get the standard error to output to a file (2.44). It output at the point that the variable was declared, before it got to the echo line. The error file was created but was empty. I got it to work by using the following: VAR=$(cat file.txt 2> stderr.txt)
@debayannew5083
@debayannew5083 Год назад
@linuxhint #/bin/Bash PS3="Select a car company : " cars=("Alto" "Sumo" "Dzire" "Scorpio") for car in "{$cars[@]}" do case $car in "Alto") echo "You choose Alto" ;; "Sumo") echo "You choose Sumo" ;; "Scorpio") echo "You choose Scorpio" ;; "Quit") break ;; "*") echo "You chosse invalid option $REPLY";; esac done Neither reviving any error or any option in output. can anyone suggest how to resolve? TIA.
Далее
Become a bash scripting pro - full course
36:00
Просмотров 54 тыс.
Linux File System/Structure Explained!
15:59
Просмотров 4,1 млн
MILLION JAMOASI 2024 4K
2:17:51
Просмотров 12 млн
A Beginner's Introduction to BASH Shell Scripting
44:24
Is Windows RUINING your Coding Career?
10:52
Просмотров 99 тыс.
BASH scripting will change your life
14:18
Просмотров 1 млн
Compilers, How They Work, And Writing Them From Scratch
23:53
Beginner's Guide to the Bash Terminal
1:14:37
Просмотров 2,3 млн
why do header files even exist?
10:53
Просмотров 399 тыс.