Shishu

test os in bash

Dec 5th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.85 KB | None | 0 0
  1. gub@cseit:~$ ld
  2. ld: no input files
  3. gub@cseit:~$ cd Documents
  4. gub@cseit:~/Documents$ mkdir Tushar
  5. gub@cseit:~/Documents$ cd Tushar
  6. gub@cseit:~/Documents/Tushar$ which bash >new.sh
  7. gub@cseit:~/Documents/Tushar$ ls
  8. new.sh
  9. gub@cseit:~/Documents/Tushar$ chmod +x new.sh
  10. gub@cseit:~/Documents/Tushar$ gedit new.sh
  11. gub@cseit:~/Documents/Tushar$ gedit new.sh
  12. gub@cseit:~/Documents/Tushar$ /new.sh
  13. bash: /new.sh: No such file or directory
  14. gub@cseit:~/Documents/Tushar$ ./new.sh
  15.  
  16.  
  17.  
  18. #!/bin/bash
  19. echo -n "enter a number"
  20. read n
  21. for ((i=1;i<=n; i++))
  22. do
  23. echo "Output $i"
  24. done
  25.  
  26. ---------------------------------
  27.  
  28. #!/bin/bash
  29. echo -n "enter a number"
  30. read n
  31. sum=0
  32. for ((i=1;i<=n; i++))
  33. do
  34. sum=$((sum+i))
  35. done
  36. echo "Output is $sum"
  37.  
  38. ----------------------------
  39.  
  40.  
  41.  
  42. Taking input in array :
  43. >>>>>>>>>>>>>>>>>>>>>>
  44.  
  45. #!/bin/bash
  46. echo -n "enter limit: "
  47. read n
  48. echo "Enter Numbers: "
  49. for ((i=0;i<n; i++))
  50. do
  51. read a[$i]
  52. done
  53.  
  54.  
  55. ##!/bin/bash
  56. echo -n "enter limit: "
  57. read n
  58. echo "Enter Numbers: "
  59.  
  60. #!/bin/bash
  61.  echo "Enter the first number :"
  62. read a
  63. echo "Enter the second number : "
  64. read b
  65.  
  66. if [ $a -gt $b ]
  67. then
  68. num=$a
  69. den=$b
  70. else
  71. num=$b
  72. den=$a
  73. fi
  74. r=`expr $num % $den`
  75.  
  76. while [ $r -ne 0 ]
  77. do
  78. num=$den
  79. den=$r
  80. r=`expr $num % $den`
  81. done
  82.  
  83. gcd=$den
  84. lcm=`expr $a \* $b / $gcd`
  85.  
  86. echo " The LCM of $a and $b is : $lcm"
  87. echo " The GCD of $a and $b is : $gcd"
  88.  
  89. leaf year...
  90.  
  91. echo "Enter Year:"
  92. read y
  93.  
  94. year=$y
  95.  
  96. y=$(( $y % 4 ))
  97. if [ $y -eq 0 ]
  98. then
  99.     echo "$year is Leap Year!"
  100. else
  101.     echo "$year is not a Leap Year!"
  102. fi
  103.  
  104.  
  105.  
  106.  
  107. prime number...
  108.  
  109. echo "Enter a number: "
  110. read num
  111. i=2
  112. f=0
  113. while [ $i -le `expr $num / 2` ]
  114. do
  115. if [ `expr $num % $i` -eq 0 ]
  116. then
  117. f=1
  118. fi
  119. i=`expr $i + 1`
  120. done
  121. if [ $f -eq 1 ]
  122. then
  123. echo "The number is composite"
  124. else
  125. echo "The number is Prime"
  126. fi
  127.  
  128. Armstrong number or not...
  129. echo "Enter a number: "
  130. read c
  131.  
  132. x=$c
  133. sum=0
  134. r=0
  135. n=0
  136. while [ $x -gt 0 ]
  137. do
  138. r=`expr $x % 10`
  139. n=`expr $r \* $r \* $r`
  140. sum=`expr $sum + $n`
  141. x=`expr $x / 10`
  142. done
  143.  
  144. if [ $sum -eq $c ]
  145. then
  146. echo "It is an Armstrong Number."
  147. else
  148. echo "It is not an Armstrong Number."
  149. fi
  150.  
  151. factorial number....
  152. echo "Enter a number"
  153. read num
  154.  
  155. fact=1
  156.  
  157. while [ $num -gt 1 ]
  158. do
  159.   fact=$((fact * num))  #fact = fact * num
  160.   num=$((num - 1))      #num = num - 1
  161. done
  162.  
  163. echo $fact
  164.  
  165.  
  166.  
  167. palindrome.....
  168. echo "enter the string "
  169. read name
  170. name1=$(echo $name | rev)
  171. if [ $name = $name1 ]
  172. then
  173. echo "$name is palindrome"
  174. else
  175. echo "$name is not a palindrome"
  176. fi
  177.  
  178. sum of natural ...
  179.  echo "Sum of n natural numbers \n”
  180. echo "Enter the value of n "
  181. read n
  182. i = 0
  183. sum = 0
  184. while[$i –lt $n]
  185. do
  186. sum=’expr $sum + expr $i’
  187. i = ‘expr $i + 1’
  188. done
  189. echo "Sum of n natural numbers are : $sum”
  190.  
  191. #shell script to check whether a number is positive or negative
  192.  
  193. echo "Enter a Number"
  194. read num
  195.  
  196. if [ $num -lt 0 ]
  197. then
  198.     echo "Negative"
  199. elif [ $num -gt 0 ]
  200. then
  201.     echo "Positive"
  202. else
  203.     echo "Neither Positive Nor Negative"
  204. fi
  205.  
  206. odd or even....
  207. echo -n "Enter numnber : "
  208. read n
  209.  
  210. rem=$(( $n % 2 ))
  211.  
  212. if [ $rem -eq 0 ]
  213. then
  214.   echo "$n is even number"
  215. else
  216.   echo "$n is odd number"
  217. fi
  218.  
  219. addition using loop....
  220. n=$1
  221. result=0
  222. j=0
  223.  
  224. ADD(){
  225.     result=`expr $result + $j`
  226. }
  227.  
  228. #for (( i=1; i<=$n; i++ ))
  229. for i in {0..$n..1}
  230. do
  231.     ADD
  232.     j=`expr $j + $1`
  233. done
  234.  
  235. echo $result
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242. …….
  243. #!/bin/bash
  244.  
  245. num1=1
  246. num2=10
  247. if [ $num1 -gt $num2 ]; then
  248.                echo "number  one is greather  "
  249. else
  250.          echo "number two is greater"
  251. fi
  252.  
  253.  
  254. @for comapre  number
  255. ...................................
  256. #!/bin/bash
  257.  
  258. num1=1
  259. num2=10
  260. if [ $num1 -eq $num2 ]; then
  261.                echo "number  is equel  "
  262. else
  263.          echo "not equel"
  264. fi
  265.  
  266. @for check odd or even number
  267. ......................
  268. #!/bin/bash
  269.  
  270. echo -n "please enter a number"
  271. read n
  272. check=$(($n % 2))
  273. if [ $check -eq 0 ];then
  274. echo "$n is an even number"
  275. else
  276. echo "$n is an odd number"
  277. fi;
  278. -------------------------------
  279. @for string comparisom
  280.  
  281.  
  282. #!/bin/bash
  283.  
  284. num1="jahid"
  285. num2="arif"
  286. if [ $num1 = $num2 ]; then
  287.                echo "name is equal  "
  288. else
  289.          echo "not equal"
  290. fi
  291. -----------------------
  292. @FOR counting
  293.  
  294. #!/bin/bash
  295.  
  296. COUNT=6
  297. while [ $COUNT -gt 0 ]; do
  298. echo value of count is: $COUNT
  299. let COUNT=COUNT-1
  300. done
  301. ----------------
  302. @ for reverse
  303. #!/bin/bash
  304.  
  305. COUNT=1
  306. while [ $COUNT -lt 7 ]; do
  307. echo value of count is: $COUNT
  308. let COUNT=COUNT+1
  309. done
  310.  
  311. -----------------------
  312. #!/bin/bash
  313.  
  314. COUNT=0
  315. until [ $COUNT -gt 5 ]; do
  316. echo value of count is: $COUNT
  317. let COUNT=COUNT+1
  318. done
  319. @ addition
  320.  
  321. echo '#### let ###'
  322. let addition=3+5
  323. echo "3+5 =" $addition
  324.  
  325. @subtraction
  326.  
  327. echo '#### let ###'
  328. let subtraction=5-3
  329. echo $subtraction
  330.  
  331.  
  332. @power of
  333. echo '#### let ###'
  334. let poweroftwo=2**2
  335. echo "2^ 2=" $poweroftwo
  336.  
  337. @mathmatatics
  338.  
  339. echo 2^8 =$[ 2** 8 ]
Advertisement
Add Comment
Please, Sign In to add comment