Advertisement
sandervanvugt

bash4H feb21

Feb 2nd, 2021
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.36 KB | None | 0 0
  1. ######## SUBSHELLS
  2. student@student-virtual-machine:~/bash-scripting$ cat colors
  3. COLOR=red
  4. student@student-virtual-machine:~/bash-scripting$ cat use-colors.sh
  5. #!/bin/bash
  6.  
  7. echo the color is $COLOR
  8. student@student-virtual-machine:~/bash-scripting$ chmod +x use-colors.sh
  9. student@student-virtual-machine:~/bash-scripting$ ./use-colors.sh
  10. the color is
  11. student@student-virtual-machine:~/bash-scripting$ COLOR=yellow
  12. student@student-virtual-machine:~/bash-scripting$ ./use-colors.sh
  13. the color is
  14. student@student-virtual-machine:~/bash-scripting$ export COLOR=yellow
  15. student@student-virtual-machine:~/bash-scripting$ ./use-colors.sh
  16. the color is yellow
  17. student@student-virtual-machine:~/bash-scripting$ vim use-colors.sh
  18. student@student-virtual-machine:~/bash-scripting$ vim use-colors.sh
  19. student@student-virtual-machine:~/bash-scripting$ cat use-colors.sh
  20. #!/bin/bash
  21.  
  22. . colors
  23.  
  24. echo the color is $COLOR
  25. student@student-virtual-machine:~/bash-scripting$ ./use-colors.sh
  26. the color is red
  27.  
  28. ##########
  29. student@student-virtual-machine:~/bash-scripting$ cat je.sh
  30. #!/bin/bash
  31.  
  32. [ ! -d ~/sysconfig ] && mkdir ~/sysconfig
  33.  
  34. echo PLANET=moon > ~/sysconfig/planets
  35.  
  36. . ~/sysconfig/planets
  37.  
  38. echo Your current planet is $PLANET
  39.  
  40. ##########student@student-virtual-machine:~/bash-scripting$ echo $?
  41. 6
  42. student@student-virtual-machine:~/bash-scripting$ cat script8c
  43. #!/bin/bash
  44.  
  45. if [ ! -f /etc/hostss ]
  46. then
  47. echo criticial error
  48. exit 6
  49. fi
  50.  
  51. echo file does exist
  52.  
  53.  
  54. ########
  55. #!/bin/bash
  56.  
  57. sudo useradd $1
  58. #echo useradd $1
  59.  
  60. if [ $? -eq 0 ]
  61. then
  62. echo user created successfully
  63. else
  64. echo user not created successfully
  65. fi
  66.  
  67. exit 0
  68.  
  69. #########
  70. student@student-virtual-machine:~/bash-scripting$ cat mz.sh
  71. #!/bin/bash
  72.  
  73. sudo useradd $1
  74. #echo useradd $1
  75.  
  76. if [ $? -eq 0 ]
  77. then
  78. echo user created successfully
  79. else
  80. echo user not created successfully
  81. fi
  82.  
  83. exit 0
  84. student@student-virtual-machine:~/bash-scripting$ cat ts.sh
  85. #!/bin/bash
  86.  
  87. # This is the comment
  88.  
  89. if sudo useradd $1
  90. then
  91. echo "User created successfully"
  92. else
  93. echo "User not created successfully"
  94. fi
  95.  
  96. exit 0
  97.  
  98. ###########
  99. student@student-virtual-machine:~/bash-scripting$ history
  100. 1 ls
  101. 2 echo $BASH
  102. 3 sudo apt install vim git bash-completion
  103. 4 git clone https://github.com/sandervanvugt/bash-script
  104. 5 git clone https://github.com/sandervanvugt/bash-scripting
  105. 6 cd bash-scripting/
  106. 7 ls
  107. 8 chsh --help
  108. 9 history
  109. 10 ls
  110. 11 vim script1
  111. 12 ls /etc/hosts
  112. 13 echo $?
  113. 14 ls hweriughiuh
  114. 15 echo $?
  115. 16 vim script1
  116. 17 script1
  117. 18 echo $PATH
  118. 19 pwd
  119. 20 ls
  120. 21 ./script1
  121. 22 ls -l
  122. 23 chmod +x script1
  123. 24 ./script1
  124. 25 history
  125. 26 ./countdown 3
  126. 27 vim script2
  127. 28 cat script2
  128. 29 ./script2
  129. 30 ls -l
  130. 31 chmod +x scr*
  131. 32 ls -l
  132. 33 cat script2
  133. 34 ./script2
  134. 35 vim subshell.txt
  135. 36 vim colors
  136. 37 vim use-colors.sh
  137. 38 cat colors
  138. 39 cat use-colors.sh
  139. 40 chmod +x use-colors.sh
  140. 41 ./use-colors.sh
  141. 42 COLOR=yellow
  142. 43 ./use-colors.sh
  143. 44 export COLOR=yellow
  144. 45 ./use-colors.sh
  145. 46 vim use-colors.sh
  146. 47 cat use-colors.sh
  147. 48 ./use-colors.sh
  148. 49 vim use-colors.sh
  149. 50 ./countdown 13
  150. 51 vim je.sh
  151. 52 chmod +x je.sh
  152. 53 ./je.sh
  153. 54 chmod +x je.sh
  154. 55 vim je.sh
  155. 56 ./je.sh
  156. 57 vim je.sh
  157. 58 ./je.sh
  158. 59 vim je.sh
  159. 60 man test
  160. 61 vim je.sh
  161. 62 ./je.sh
  162. 63 vim je.sh
  163. 64 ./je.sh
  164. 65 cat je.sh
  165. 66 history
  166. 67 vim countdown
  167. 68 vim script3
  168. 69 echo $(( 2 * 30 ))
  169. 70 echo $( 2 * 30 )
  170. 71 vim script3
  171. 72 ./script3 a b c d e f g h i jk l m n o p
  172. 73 cat script3
  173. 74 echo $$$$$
  174. 75 echo \$$$$$
  175. 76 echo '$$$$$'
  176. 77 blah lisa
  177. 78 ./countdown 3
  178. 79 vim je.sh
  179. 80 vim je2.sh
  180. 81 chmod +x je2.sh
  181. 82 ./je2.sh
  182. 83 ./je2.sh linda lucy lori
  183. 84 vim je2.sh
  184. 85 vim script4
  185. 86 ./script4 a b c d e
  186. 87 cat script4
  187. 88 vim script4
  188. 89 ./script4 a b c d e
  189. 90 touch iwrhgi
  190. 91 ./countdown 3
  191. 92 vim kc.sh
  192. 93 ip a
  193. 94 chmod +x kc.sh
  194. 95 ./kc.sh 8 1 7 6 5
  195. 96 vim kc.sh
  196. 97 cd /lib
  197. 98 ls
  198. 99 cd kernel/
  199. 100 ls
  200. 101 cd ..
  201. 102 cd
  202. 103 uname -r
  203. 104 find / -name $(uname -r)
  204. 105 sudo find / -name $(uname -r) 2>/dev/null
  205. 106 cd /usr/lib/modules
  206. 107 ls
  207. 108 cd $(uname -r)
  208. 109 cd ..
  209. 110 cd `uname -r`
  210. 111 cd
  211. 112 cd bash-scripting/
  212. 113 ./countdown 3
  213. 114 vim dv.sh
  214. 115 bash dv.sh
  215. 116 ls
  216. 117 vim script6
  217. 118 ./script6 /usr/bin/blah
  218. 119 vim script6
  219. 120 ./script6 /usr/bin/blah
  220. 121 vim script6
  221. 122 ./script6 /usr/bin/blah
  222. 123 vim script6
  223. 124 vim script7
  224. 125 ./countdown 4
  225. 126 ls
  226. 127 vim je2.sh
  227. 128 vim je3.sh
  228. 129 chmod +x je3.sh
  229. 130 ./je3.sh
  230. 131 vim je3.sh
  231. 132 vim script8
  232. 133 cat /etc/passwd
  233. 134 cut -d : -f 1 /etc/passwd
  234. 135 vim script8
  235. 136 sudo useradd alex
  236. 137 sudo useradd alexander
  237. 138 ./script8 alex
  238. 139 ./script8 khkuhi
  239. 140 vim script8
  240. 141 cp script8 script8b
  241. 142 vim script8b
  242. 143 chmod +x script8b
  243. 144 ./script8b alex
  244. 145 ./script8b erblhjki
  245. 146 vim script8b
  246. 147 vim script8c
  247. 148 chmod +x script8c
  248. 149 ./script8c
  249. 150 vim script8c
  250. 151 ./script8c
  251. 152 echo $?
  252. 153 cat script8c
  253. 154 vim users
  254. 155 grep alex users
  255. 156 grep ^alex users
  256. 157 grep alex$ users
  257. 158 grep ^alex$ users
  258. 159 vim script8
  259. 160 vim script8c
  260. 161 man test
  261. 162 test -f /etc/hosts
  262. 163 echo $0
  263. 164 test -f /etc/hosts
  264. 165 echo $?
  265. 166 test ! -f /etc/hosts
  266. 167 echo $?
  267. 168 [ ! -f /etc/hosts ]
  268. 169 echo $?
  269. 170 less /etc/network/if-post-down.d/wireless-tools
  270. 171 vim script8
  271. 172 ./script8 alex
  272. 173 vim script8
  273. 174 ./countdown 12
  274. 175 vim mz.sh
  275. 176 chmod +x mz.sh
  276. 177 ./mz.sh
  277. 178 ./mz.sh bob
  278. 179 vim mz.sh
  279. 180 ./mz.sh
  280. 181 bash -x mz.sh
  281. 182 vim mz.sh
  282. 183 man test
  283. 184 vim mz.sh
  284. 185 ./mz.sh
  285. 186 vim mz.sh
  286. 187 ./mz.sh
  287. 188 vim mz.sh
  288. 189 ./mz.sh bill
  289. 190 cat mz.sh
  290. 191 vim script9
  291. 192 cp script9 script9b
  292. 193 vim script9b
  293. 194 chmod +x script9b
  294. 195 ./script9b
  295. 196 echo $?
  296. 197 ./script9b jhyki
  297. 198 vim script9b
  298. 199 [ -f /etc/khkiu ] || echo failing
  299. 200 [ -f /etc/hosts ] || echo failing
  300. 201 [ -f /etc/hosts ] && echo successfull
  301. 202 [ -f /etc/hosthjgjgys ] && echo successfull
  302. 203 ./countdown 3
  303. 204 vim ts.sh
  304. 205 chmod +x ts.sh
  305. 206 ./ts.sh
  306. 207 ./ts.sh bob
  307. 208 ./ts.sh ben
  308. 209 history
  309. 210 cat mz.sh
  310. 211 cat ts.sh
  311. 212 vim sb.sh
  312. 213 man test
  313. 214 vim sb.sh
  314. 215 chmod +x sb.sh
  315. 216 ./sb.sh
  316. 217 vim sb.sh
  317. 218 ./sb.sh
  318. 219 vim sb.sh
  319. 220 ./sb.sh
  320. 221 ls -l /etc/shadow
  321. 222 ls
  322. 223 vim script10
  323. 224 ./script10 5
  324. 225 vim script11
  325. 226 ./script11 1
  326. 227 vim script11
  327. 228 ./script11 1
  328. 229 vim script11
  329. 230 ./script11 1
  330. 231 bash -x script11 1
  331. 232 vim script11
  332. 233 ./script11 1
  333. 234 bash -x ./script11 1
  334. 235 ls
  335. 236 vim script11
  336. 237 ./script11 1
  337. 238 vim script11
  338. 239 ./script11 1
  339. 240 vim script11
  340. 241 ./script11 1
  341. 242 history
  342.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement