mdelatorre

BASH stuff

Aug 23rd, 2016
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Hello World:
  2. #!/bin/bash
  3. echo Hello World!
  4.  
  5. Shebang:
  6. #!/usr/bin/python3
  7. print("I'm beeing run in python3")
  8.  
  9. Simple Backup:
  10. #!/bin/bash
  11. tar -cZf /var/backup.tgz /home/linux
  12.  
  13. Variables:
  14. #!/bin/bash
  15. variable="Inhalt"
  16. echo #variable
  17.  
  18. If/Else:
  19. #!/bin/bash
  20. variable="Inhalt"
  21. if [ $variable == "Inhalt" ]
  22. then
  23.     echo true
  24. else
  25.     echo false
  26. fi
  27.  
  28. For-Loop:
  29. #!/bin/bash
  30. for i in $(seq 1 10)
  31. do
  32.     echo $i
  33. done
  34.  
  35. For item in x:
  36. #!/bin/bash
  37. for item in `ls`
  38. do
  39.     echo item: $item
  40. done
  41.  
  42. While:
  43. #!/bin/bash
  44. COUNTER=0
  45. while [ $COUNTER -lt 10 ]
  46. do
  47.     echo $COUNTER
  48.     let COUNTER=COUNTER+1
  49. done
  50.  
  51. Until:
  52. #!/bin/bash
  53. COUNTER=20
  54. until [ counter -lt 10 ]
  55. do
  56.     echo $COUNTER
  57.     let COUNTER-=1
  58. done
  59.  
  60. Funktion:
  61. #!/bin/bash
  62. function hello{
  63.     echo Hello!
  64. }
  65. hello
  66. exit
  67.  
  68. Funktion und Parameter:
  69. #!/bin/bash
  70. function e{
  71.     echo $1
  72. }
  73. e hello
  74. e hello world
  75. e "Hello World!"
  76.  
  77. Interface:
  78. #!/bin/bash
  79. OPTIONS="Hello Done"
  80. select opt in $OPTIONS
  81. do
  82.     if [ "$opt" = "Quit" ]
  83.     then
  84.         echo done
  85.         exit
  86.     elif [ "$opt" = "Hello" ]
  87.     then
  88.         echo Hello World!
  89.     else
  90.         clear
  91.         echo bad option
  92.     fi
  93. done
  94.  
  95. Debug:
  96. #!/bin/bash -x
Add Comment
Please, Sign In to add comment