├── LICENSE ├── README.md ├── SUMMARY.md └── refrences.md /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cheatsheet 2 | 3 | ### Example 4 | 5 | ``` 6 | #!/bin/bash 7 | 8 | NAME="Payam" 9 | echo "Hello $NAME!" 10 | 11 | exit 0 12 | ``` 13 | 14 | ### Variables: 15 | 16 | ``` 17 | varname=value # defines a variable 18 | varname=value command # defines a variable to be in the environment of a particular subprocess 19 | echo $varname # checks a variable's value 20 | read # reads a string from the input and assigns it to a variable 21 | let = # performs mathematical calculation using operators like +, -, *, /, % 22 | export VARNAME=value # defines an environment variable (will be available in subprocesses) 23 | ``` 24 | 25 | ``` 26 | #Special shell variables 27 | echo $$ # prints process ID of the current shell 28 | echo $! # prints process ID of the most recently invoked background job 29 | echo $? # displays the exit status of the last command 30 | echo $0 # display Filename of the shell script 31 | ``` 32 | 33 | ### Quoting: 34 | 35 | ``` 36 | \c #Take character c literally. 37 | `cmd` #Run cmd and replace it in the line of code with its output. 38 | "whatever" #Take whatever literally, after first interpreting $, `...`, \ 39 | 'whatever' #Take whatever absolutely literally. 40 | 41 | #Example: 42 | match=`ls *.bak` #Puts names of .bak files into shell variable match. 43 | echo \* #Echos * to screen, not all filename as in: echo * 44 | echo '$1$2hello' #Writes literally $1$2hello on screen. 45 | echo "$1$2hello" #Writes value of parameters 1 and 2 and string hello. 46 | ``` 47 | 48 | ### Redirection 49 | 50 | ``` 51 | python hello.py > output.txt # stdout to (file) 52 | python hello.py >> output.txt # stdout to (file), append 53 | python hello.py 2> error.log # stderr to (file) 54 | python hello.py 2>&1 # stderr to stdout 55 | python hello.py 2>/dev/null # stderr to (null) 56 | python hello.py &>/dev/null # stdout and stderr to (null) 57 | python hello.py < foo.txt # feed foo.txt to stdin for python 58 | ``` 59 | 60 | ### Brace expansion 61 | 62 | ``` 63 | {A,B} Same as A B 64 | {A,B}.js Same as A.js B.js 65 | {1..5} Same as 1 2 3 4 5 66 | ``` 67 | 68 | ## Parameter expansions 69 | 70 | ### Basics 71 | 72 | ``` 73 | name="John" 74 | echo ${name} 75 | echo ${name/J/j} #=> "john" (substitution) 76 | echo ${name:0:2} #=> "Jo" (slicing) 77 | echo ${name::2} #=> "Jo" (slicing) 78 | echo ${name::-1} #=> "Joh" (slicing) 79 | echo ${name:(-1)} #=> "n" (slicing from right) 80 | echo ${name:(-2):1} #=> "h" (slicing from right) 81 | echo ${food:-Cake} #=> $food or "Cake" 82 | 83 | length=2 84 | echo ${name:0:length} #=> "Jo" 85 | ``` 86 | 87 | ``` 88 | STR="/path/to/foo.cpp" 89 | echo ${STR%.cpp} # /path/to/foo 90 | echo ${STR%.cpp}.o # /path/to/foo.o 91 | echo ${STR%/*} # /path/to 92 | 93 | echo ${STR##*.} # cpp (extension) 94 | echo ${STR##*/} # foo.cpp (basepath) 95 | 96 | echo ${STR#*/} # path/to/foo.cpp 97 | echo ${STR##*/} # foo.cpp 98 | 99 | echo ${STR/foo/bar} # /path/to/bar.cpp 100 | STR="Hello world" 101 | echo ${STR:6:5} # "world" 102 | echo ${STR: -5:5} # "world" 103 | SRC="/path/to/foo.cpp" 104 | BASE=${SRC##*/} #=> "foo.cpp" (basepath) 105 | DIR=${SRC%$BASE} #=> "/path/to/" (dirpath) 106 | ``` 107 | 108 | ### Substitution 109 | 110 | ``` 111 | ${FOO%suffix} Remove suffix 112 | ${FOO#prefix} Remove prefix 113 | ${FOO%%suffix} Remove long suffix 114 | ${FOO##prefix} Remove long prefix 115 | ${FOO/from/to} Replace first match 116 | ${FOO//from/to} Replace all 117 | ${FOO/%from/to} Replace suffix 118 | ${FOO/#from/to} Replace prefix 119 | ``` 120 | 121 | ### Length 122 | 123 | ``` 124 | ${#FOO} Length of $FOO 125 | ``` 126 | 127 | ### Default Values 128 | 129 | ``` 130 | ${FOO:-val} $FOO, or val if unset (or null) 131 | ${FOO:=val} Set $FOO to val if unset (or null) 132 | ${FOO:+val} val if $FOO is set (and not null) 133 | ${FOO:?message} Show error message and exit if $FOO is unset (or null) 134 | 135 | #Omitting the : removes the (non)nullity checks, 136 | #e.g. ${FOO-val} expands to val if unset otherwise $FOO. 137 | ``` 138 | 139 | ### Comment 140 | 141 | ``` 142 | # Single line comment 143 | : ' 144 | This is a 145 | multi line 146 | comment 147 | ' 148 | ``` 149 | 150 | ### Substrings 151 | 152 | ``` 153 | ${FOO:0:3} Substring (position, length) 154 | ${FOO:(-3):3} Substring from the right 155 | ``` 156 | 157 | ### Manipulations 158 | 159 | ``` 160 | STR="HELLO WORLD!" 161 | echo ${STR,} #=> "hELLO WORLD!" (lowercase 1st letter) 162 | echo ${STR,,} #=> "hello world!" (all lowercase) 163 | 164 | STR="hello world!" 165 | echo ${STR^} #=> "Hello world!" (uppercase 1st letter) 166 | echo ${STR^^} #=> "HELLO WORLD!" (all uppercase) 167 | ``` 168 | 169 | ## Conditionals: 170 | 171 | ### Test Operators 172 | 173 | In Bash, the `test` command takes one of the following syntax forms: 174 | 175 | * **test EXPRESSION** 176 | * **\[ EXPRESSION ]** 177 | * **\[\[ EXPRESSION ]]** 178 | 179 | To make the script portable, prefer using the old test `[` command which is available on all POSIX shells. The new upgraded version of the `test` command `[[` (double brackets) is supported on most modern systems using Bash, Zsh, and Ksh as a default shell. To negate the test expression, use the logical `NOT` (`!`) operator. 180 | 181 | ### Checking Numbers 182 | 183 | _Note that a shell variable could contain a string that represents a number. If you want to check the numerical value use one of the following:_ 184 | 185 | ``` 186 | [[ NUM -eq NUM ]] Equal 187 | [[ NUM -ne NUM ]] Not equal 188 | [[ NUM -lt NUM ]] Less than 189 | [[ NUM -le NUM ]] Less than or equal 190 | [[ NUM -gt NUM ]] Greater than 191 | [[ NUM -ge NUM ]] Greater than or equal 192 | ``` 193 | 194 | ### Checking Strings 195 | 196 | ``` 197 | [[ -z STRING ]] Empty string 198 | [[ -n STRING ]] Not empty string 199 | [[ STRING == STRING ]] Equal 200 | [[ STRING != STRING ]] Not Equal 201 | 202 | ``` 203 | 204 | ### Checking files 205 | 206 | ``` 207 | [[ -e FILE ]] Exists 208 | [[ -r FILE ]] Readable 209 | [[ -h FILE ]] Symlink 210 | [[ -d FILE ]] Directory 211 | [[ -w FILE ]] Writable 212 | [[ -s FILE ]] Size is > 0 bytes 213 | [[ -f FILE ]] File 214 | [[ -x FILE ]] Executable 215 | [[ FILE1 -nt FILE2 ]] 1 is more recent than 2 216 | [[ FILE1 -ot FILE2 ]] 2 is more recent than 1 217 | [[ FILE1 -ef FILE2 ]] Same files 218 | ``` 219 | 220 | ### More conditions: 221 | 222 | ``` 223 | [[ -o noclobber ]] If OPTIONNAME is enabled 224 | [[ ! EXPR ]] Not 225 | [[ X && Y ]] And 226 | [[ X || Y ]] Or 227 | ``` 228 | 229 | ### if statement: 230 | 231 | ``` 232 | #if Statement 233 | 234 | echo -n "Enter a number: " 235 | read VAR 236 | 237 | if [[ $VAR -gt 10 ]] 238 | then 239 | echo "The variable is greater than 10." 240 | fi 241 | ``` 242 | 243 | ``` 244 | #if..else Statement 245 | 246 | echo -n "Enter a number: " 247 | read VAR 248 | 249 | if [[ $VAR -gt 10 ]] 250 | then 251 | echo "The variable is greater than 10." 252 | else 253 | echo "The variable is equal or less than 10." 254 | fi 255 | ``` 256 | 257 | ``` 258 | #if..elif..else Statement 259 | 260 | echo -n "Enter a number: " 261 | read VAR 262 | 263 | if [[ $VAR -gt 10 ]] 264 | then 265 | echo "The variable is greater than 10." 266 | elif [[ $VAR -eq 10 ]] 267 | then 268 | echo "The variable is equal to 10." 269 | else 270 | echo "The variable is less than 10." 271 | fi 272 | ``` 273 | 274 | ``` 275 | # Nested if Statements 276 | echo -n "Enter the first number: " 277 | read VAR1 278 | echo -n "Enter the second number: " 279 | read VAR2 280 | echo -n "Enter the third number: " 281 | read VAR3 282 | 283 | if [[ $VAR1 -ge $VAR2 ]] 284 | then 285 | if [[ $VAR1 -ge $VAR3 ]] 286 | then 287 | echo "$VAR1 is the largest number." 288 | else 289 | echo "$VAR3 is the largest number." 290 | fi 291 | else 292 | if [[ $VAR2 -ge $VAR3 ]] 293 | then 294 | echo "$VAR2 is the largest number." 295 | else 296 | echo "$VAR3 is the largest number." 297 | fi 298 | fi 299 | ``` 300 | 301 | ## Loops: 302 | 303 | ### for: 304 | 305 | ``` 306 | #basic for loop 307 | for i in 1 2 3 4 5 308 | do 309 | echo "Welcome $i times" 310 | done 311 | ``` 312 | 313 | ``` 314 | #Basic for loop 315 | for i in /etc/rc.*; do 316 | echo $i 317 | done 318 | ``` 319 | 320 | ``` 321 | #Ranges 322 | for i in {1..5}; do 323 | echo "Welcome $i" 324 | done 325 | ``` 326 | 327 | ``` 328 | #C-Like for loop 329 | for ((i = 0 ; i < 100 ; i++)); do 330 | echo $i 331 | done 332 | ``` 333 | 334 | ``` 335 | #with step size 336 | for i in {5..50..5}; do 337 | echo "Welcome $i" 338 | done 339 | ``` 340 | 341 | ### while: 342 | 343 | ``` 344 | n=1 345 | 346 | while [ $n -le 5 ] 347 | do 348 | echo "Welcome $n times." 349 | n=$(( n+1 )) 350 | done 351 | ``` 352 | 353 | ``` 354 | #Using ((expression)) Format With The While Loop 355 | n=1 356 | while (( $n <= 5 )) 357 | do 358 | echo "Welcome $n times." 359 | n=$(( n+1 )) 360 | done 361 | ``` 362 | 363 | ``` 364 | #for ever 365 | while true; do 366 | ··· 367 | done 368 | ``` 369 | 370 | ``` 371 | # Reading a test file: 372 | ###example1/2: 373 | cat /etc/resolv.conf | while read line; do 374 | echo $line 375 | done 376 | 377 | ###example2/2: 378 | file=/etc/resolv.conf 379 | while IFS= read -r line 380 | do 381 | echo $line 382 | done < "$file" 383 | 384 | ### Reading A Text File With Separate Fields: 385 | file=/etc/resolv.conf 386 | # set field separator to a single white space 387 | while IFS=' ' read -r f1 f2 388 | do 389 | echo "field # 1 : $f1 ==> field #2 : $f2" 390 | done < "$file" 391 | ``` 392 | 393 | ### Until: 394 | 395 | ``` 396 | #!/bin/bash 397 | 398 | counter=0 399 | 400 | until [ $counter -gt 5 ] 401 | do 402 | echo Counter: $counter 403 | ((counter++)) 404 | done 405 | ``` 406 | 407 | ### Case: 408 | 409 | ``` 410 | Case/switch 411 | case "$1" in 412 | start | up) 413 | vagrant up 414 | ;; 415 | 416 | *) 417 | echo "Usage: $0 {start|stop|ssh}" 418 | ;; 419 | esac 420 | ``` 421 | 422 | ### Functions: 423 | 424 | ``` 425 | # Defining functions: 426 | myfunc() { 427 | echo "hello $1" 428 | } 429 | # Same as above (alternate syntax) 430 | function myfunc() { 431 | echo "hello $1" 432 | } 433 | myfunc "John" 434 | ``` 435 | 436 | ``` 437 | #Returning values: 438 | myfunc() { 439 | local myresult='some value' 440 | echo $myresult 441 | } 442 | result="$(myfunc)" 443 | ``` 444 | 445 | ``` 446 | #Raising errors: 447 | myfunc() { 448 | return 1 449 | } 450 | if myfunc; then 451 | echo "success" 452 | else 453 | echo "failure" 454 | fi 455 | ``` 456 | 457 | ``` 458 | #Arguments: 459 | $# Number of arguments 460 | $* All arguments 461 | $@ All arguments, starting from first 462 | $1 First argument 463 | $_ Last argument of the previous command 464 | ``` 465 | 466 | ### Arrays 467 | 468 | ``` 469 | Defining arrays 470 | Fruits=('Apple' 'Banana' 'Orange') 471 | Fruits[0]="Apple" 472 | Fruits[1]="Banana" 473 | Fruits[2]="Orange" 474 | ``` 475 | 476 | ``` 477 | Operations 478 | Fruits=("${Fruits[@]}" "Watermelon") # Push 479 | Fruits+=('Watermelon') # Also Push 480 | Fruits=( ${Fruits[@]/Ap*/} ) # Remove by regex match 481 | unset Fruits[2] # Remove one item 482 | Fruits=("${Fruits[@]}") # Duplicate 483 | Fruits=("${Fruits[@]}" "${Veggies[@]}") # Concatenate 484 | lines=(`cat "logfile"`) # Read from file 485 | ``` 486 | 487 | ``` 488 | Working with arrays 489 | echo ${Fruits[0]} # Element #0 490 | echo ${Fruits[-1]} # Last element 491 | echo ${Fruits[@]} # All elements, space-separated 492 | echo ${#Fruits[@]} # Number of elements 493 | echo ${#Fruits} # String length of the 1st element 494 | echo ${#Fruits[3]} # String length of the Nth element 495 | echo ${Fruits[@]:3:2} # Range (from position 3, length 2) 496 | echo ${!Fruits[@]} # Keys of all elements, space-separated 497 | ``` 498 | 499 | ``` 500 | Iteration 501 | for i in "${arrayName[@]}"; do 502 | echo $i 503 | done 504 | ``` 505 | 506 | ### Dictionaries: 507 | 508 | ``` 509 | Defining 510 | declare -A sounds 511 | sounds[dog]="bark" 512 | sounds[cow]="moo" 513 | sounds[bird]="tweet" 514 | sounds[wolf]="howl" 515 | ``` 516 | 517 | ``` 518 | Working with dictionaries 519 | echo ${sounds[dog]} # Dog's sound 520 | echo ${sounds[@]} # All values 521 | echo ${!sounds[@]} # All keys 522 | echo ${#sounds[@]} # Number of elements 523 | unset sounds[dog] # Delete dog 524 | ``` 525 | 526 | ``` 527 | Iteration 528 | Iterate over values 529 | for val in "${sounds[@]}"; do 530 | echo $val 531 | done 532 | Iterate over keys 533 | for key in "${!sounds[@]}"; do 534 | echo $key 535 | done 536 | ``` 537 | 538 | ### Debugging 539 | 540 | ``` 541 | bash -n scriptname # don't run commands; check for syntax errors only 542 | set -o noexec # alternative (set option in script) 543 | 544 | bash -v scriptname # echo commands before running them 545 | set -o verbose # alternative (set option in script) 546 | 547 | bash -x scriptname # echo commands after command-line processing 548 | set -o xtrace # alternative (set option in script) 549 | ``` 550 | 551 | ## Miscellaneous: 552 | 553 | ``` 554 | #Numeric calculations 555 | $((a + 200)) # Add 200 to $a 556 | $(($RANDOM%200)) # Random number 0..199 557 | ``` 558 | 559 | ``` 560 | #Inspecting commands 561 | command -V cd 562 | #=> "cd is a function/alias/whatever" 563 | ``` 564 | 565 | ``` 566 | #Heredoc: 567 | cat < "Hello Sven, I'm Olga 576 | 577 | printf "1 + 1 = %d" 2 578 | #=> "1 + 1 = 2" 579 | 580 | printf "This is how you print a float: %f" 2 581 | #=> "This is how you print a float: 2.000000" 582 | ``` 583 | 584 | ``` 585 | #Reading input 586 | echo -n "Proceed? [y/n]: " 587 | read ans 588 | echo $ans 589 | 590 | #Reading Just one character: 591 | read -n 1 ans 592 | ``` 593 | 594 | ``` 595 | #Getting options 596 | while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in 597 | -V | --version ) 598 | echo $version 599 | exit 600 | ;; 601 | -s | --string ) 602 | shift; string=$1 603 | ;; 604 | -f | --flag ) 605 | flag=1 606 | ;; 607 | esac; shift; done 608 | if [[ "$1" == '--' ]]; then shift; fi 609 | ``` 610 | 611 | ``` 612 | #Check for command’s result 613 | if ping -c 1 google.com; then 614 | echo "It appears you have a working internet connection" 615 | fi 616 | ``` 617 | 618 | 619 | 620 | Payam Borosan.Goodluck 621 | -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Table of contents 2 | 3 | * [cheatsheet](README.md) 4 | * [Refrences](refrences.md) 5 | 6 | -------------------------------------------------------------------------------- /refrences.md: -------------------------------------------------------------------------------- 1 | # Refrences 2 | 3 | . 4 | 5 | [https://linuxize.com/post/bash-if-else-statement/](https://linuxize.com/post/bash-if-else-statement/) 6 | 7 | [https://bash.cyberciti.biz/guide/While_loop](https://bash.cyberciti.biz/guide/While_loop) 8 | 9 | [https://linuxize.com/post/bash-until-loop/](https://linuxize.com/post/bash-until-loop/) 10 | 11 | [https://devhints.io/bash](https://devhints.io/bash) 12 | 13 | [http://johnstowers.co.nz/pages/bash-cheat-sheet.html](http://johnstowers.co.nz/pages/bash-cheat-sheet.html) 14 | 15 | [https://github.com/LeCoupa/awesome-cheatsheets/blob/master/languages/bash.sh](https://github.com/LeCoupa/awesome-cheatsheets/blob/master/languages/bash.sh) 16 | 17 | . 18 | --------------------------------------------------------------------------------