Guest User

Untitled

a guest
May 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. # ECHO COMMAND
  4. # echo Hello World!
  5.  
  6. # VARIABLES
  7. # Uppercase by convention
  8. # Letters, numbers, underscores
  9. NAME="Bob"
  10. # echo "My name is $NAME"
  11. # echo "My name is ${NAME}"
  12.  
  13. # USER INPUT
  14. # read -p "Enter your name: " NAME
  15. # echo "Hello $NAME, nice to meet you!"
  16.  
  17. # SIMPLE IF STATEMENT
  18. # if [ "$NAME" == "Brad" ]
  19. # then
  20. # echo "Your name is Brad"
  21. # fi
  22.  
  23. # IF-ELSE
  24. # if [ "$NAME" == "Brad" ]
  25. # then
  26. # echo "Your name is Brad"
  27. # else
  28. # echo "Your name is NOT Brad"
  29. # fi
  30.  
  31. # ELSE-IF (elif)
  32. # if [ "$NAME" == "Brad" ]
  33. # then
  34. # echo "Your name is Brad"
  35. # elif [ "$NAME" == "Jack" ]
  36. # then
  37. # echo "Your name is Jack"
  38. # else
  39. # echo "Your name is NOT Brad or Jack"
  40. # fi
  41.  
  42. # COMPARISON
  43. # NUM1=31
  44. # NUM2=5
  45. # if [ "$NUM1" -gt "$NUM2" ]
  46. # then
  47. # echo "$NUM1 is greater than $NUM2"
  48. # else
  49. # echo "$NUM1 is less than $NUM2"
  50. # fi
  51.  
  52. ########
  53. # val1 -eq val2 Returns true if the values are equal
  54. # val1 -ne val2 Returns true if the values are not equal
  55. # val1 -gt val2 Returns true if val1 is greater than val2
  56. # val1 -ge val2 Returns true if val1 is greater than or equal to val2
  57. # val1 -lt val2 Returns true if val1 is less than val2
  58. # val1 -le val2 Returns true if val1 is less than or equal to val2
  59. ########
  60.  
  61. # FILE CONDITIONS
  62. # FILE="test.txt"
  63. # if [ -e "$FILE" ]
  64. # then
  65. # echo "$FILE exists"
  66. # else
  67. # echo "$FILE does NOT exist"
  68. # fi
  69.  
  70. ########
  71. # -d file True if the file is a directory
  72. # -e file True if the file exists (note that this is not particularly portable, thus -f is generally used)
  73. # -f file True if the provided string is a file
  74. # -g file True if the group id is set on a file
  75. # -r file True if the file is readable
  76. # -s file True if the file has a non-zero size
  77. # -u True if the user id is set on a file
  78. # -w True if the file is writable
  79. # -x True if the file is an executable
  80. ########
  81.  
  82. #CASE STATEMENT
  83. # read -p "Are you 21 or over? Y/N " ANSWER
  84. # case "$ANSWER" in
  85. # [yY] | [yY][eE][sS])
  86. # echo "You can have a beer :)"
  87. # ;;
  88. # [nN] | [nN][oO])
  89. # echo "Sorry, no drinking"
  90. # ;;
  91. # *)
  92. # echo "Please enter y/yes or n/no"
  93. # ;;
  94. # esac
  95.  
  96. # SIMPLE FOR LOOP
  97. # NAMES="Brad Kevin Alice Mark"
  98. # for NAME in $NAMES
  99. # do
  100. # echo "Hello $NAME"
  101. # done
  102.  
  103. # FOR LOOP TO RENAME FILES
  104. # FILES=$(ls *.txt)
  105. # NEW="new"
  106. # for FILE in $FILES
  107. # do
  108. # echo "Renaming $FILE to new-$FILE"
  109. # mv $FILE $NEW-$FILE
  110. # done
  111.  
  112. # WHILE LOOP - READ THROUGH A FILE LINE BY LINE
  113. # LINE=1
  114. # while read -r CURRENT_LINE
  115. # do
  116. # echo "$LINE: $CURRENT_LINE"
  117. # ((LINE++))
  118. # done < "./new-1.txt"
  119.  
  120. # FUNCTION
  121. # function sayHello() {
  122. # echo "Hello World"
  123. # }
  124. # sayHello
  125.  
  126. # FUNCTION WITH PARAMS
  127. # function greet() {
  128. # echo "Hello, I am $1 and I am $2"
  129. # }
  130.  
  131. # greet "Brad" "36"
  132.  
  133. # CREATE FOLDER AND WRITE TO A FILE
  134. # mkdir hello
  135. # touch "hello/world.txt"
  136. # echo "Hello World" >> "hello/world.txt"
  137. # echo "Created hello/world.txt"
Add Comment
Please, Sign In to add comment