GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — operating-system/Assignment2.txt at master · SandeshWaykar/operating-system Expand file tree/ Copy pathAssignment2.txtMore file actions 342 lines (264 loc) · 7.24 KB / Copy pathAssignment2.txtFile metadata and controls342 lines (264 loc) · 7.24 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 ASSIGNMENT NO:- 02 ROLL NO:- 200240520086 1. Write a script to create 10 directories, say a1,a2,...,a10 Report error if a directory/file exists with the same name. > #!/bin/bash echo "Enter no." read num for((i=1 ;i<=num; i++)) do mkdir a$i done mkdir: cannot create directory ‘a1’: File exists ------------------------------------------------------------------------------ 2. Write a menu based script to perform following string operations a) To find length of a string c) Copying string d) Concatenation of strings e) Compare two strings f) Reversing a string > #!/bin/bash do echo '1.Find length' echo '2.Copying string' echo '3.Concate of string' echo '4.compare to sring' echo '5.Reverse string' read str1 read option case $option in 1) echo ${#str1} ;; 2) str2=$str1 echo $str2 ;; 3)str2="Mahajan" echo $str1$str2 ;; 4) str2="Meghana" if [ $str1 == $str2 ] then echo "Equal" else echo "Not equal" fi ;; 5) echo $str1 | rev ;; ---------------------------------------------------------------------------------------------- 3.Write a shell script to rename all files in the current directory with numeric continuous value(Warning: Do this in a personal folder. Don't use Home directory) > for((i=1;i<10;i++)) do mv a$i abbbb$i done ------------------------------------------------------------------------------------------------ 4. Write a script that print environment variable(Print $HOME,$PATH,$SHELL,$HISTORY,$LOGNAME,$TERM) > echo "Path = $PATH" echo "Shell = $SHELL" echo "History = $HISTORY" echo "Logname = $LOGNAME" echo "Term = $TERM" --------------------------------------------------------------------------------------------- 5. Write a shell script to print all files permissions in current directory(Not name or other details)(Use cut commands) > ls -la | cut -b 1-10 > ls -la | cut -c 1-10 -------------------------------------------------------------------------------------------- 6. Write a shell script to print all files permissions and name of file > #!/bin/bash ls -l | awk '{ print $1 }' ---------------------------------------------------------------------------------------- 7.Write a shell script to print all files name and size greater than 5K > #!/bin/bash for i in * do if [ -e $i ] then file=`ls -l $i | awk '{print $5}'` if (( $file > 5000 )) then ls -l $i fi fi done ----------------------------------------------------------------------------------------- 1. Write a script To check given year is leap or not. > #!/bin/bash echo 'Enter a year : ' read year if (( $year%4 == 0 && $year%100 != 0 || $year%400 == 0)) then echo 'Leap Year' else echo 'Not a Leap Year' fi -------------------------------------------------------------------------------------------- 2. Write a script to print day of the week using a) elif b) case > #!/bin/bash echo 'Enter the no of Day : ' read day if [ $day == 1 ] then echo 'Sunday' elif [ $day == 2 ] then echo 'Monday' elif [ $day == 3 ] then echo 'Tuesday' elif [ $day == 4 ] then echo 'Wednesday' elif [ $day == 5 ] then echo 'Thrusday' elif [ $day == 6 ] then echo 'Friday' elif [ $day == 7 ] then echo 'Saturday' else echo 'Invalid Entry' fi ------------------------------------------------------------------------------------------- 3. a) Write a script to find biggest of three no.s b) To find avg of 3 no.s, read no.s from keyboard > #!/bin/bash echo 'Enter num1 : ' read num1 echo 'Enter num2 : ' read num2 echo 'Enter num3 : ' read num3 if (( num1 > num2 && num1 > num3 )) then echo $num1 elif (( num2 > num1 && num2 > num3 )) then echo $num2 else echo $num3 fi -------------------------------------------------------------------------------------------- 4. Write a program to check wahether given no.is even or odd > #!/bin/bash echo 'Enter a number : ' read num if (( num%2 == 0 )) then echo $num 'is Even.' else echo $num 'is Odd.' fi ---------------------------------------------------------------------------------------- 5. Write a program to print calendar of current month in next year,previous years. For eg:-sep 2014,sep 2012 if current month is sep 2013 > #!/bin/bash mon=$(date | awk '{print $3}') year=$(date | awk '{print $4}') let "prev=year-1" "next=year+1" cal $mon $prev cal $mon $year cal $mon $next --------------------------------------------------------------------------------------- 6. Write a program to find sum and product of two no.s using a) let b)expr c)bc > #!/bin/bash echo 'Enter num1 : ' read num1 echo 'Enter num2 : ' read num2 echo 'Enter num3 : ' read num3 (( avg = (( $num1+$num2+$num3 ))/3 )) echo 'Average : '$avg > #!/bin/bash echo 'Enter num1 : ' read num1 echo 'Enter num2 : ' read num2 let "prodlet=num1*num2" prodExp=$(expr $num1 \* $num2) echo 'Let : ' echo $prodlet echo 'Expr : ' echo $prodExp echo 'BC : ' echo $num1 \* $num2 | bc ------------------------------------------------------------------------------------------ 7. Write a script to generate Fibonacci series. > #!/bin/bash echo 'Enter the range till you want to calculate the Fibonaccci Series : ' read range i=1 prev=0 newprev=0 while (( $i+$prev < $range )) do echo $(expr $prev + $i) newprev=$prev prev=$i i=$(expr $newprev + $i) done ---------------------------------------------------------------------------------------- 8. Write a shell script to reverse the single strings. > #!/bin/bash echo 'Enter a string : ' read str rev="" len=${#str} for (( i=$len; i>0; i-- )) do temp=$(expr $str | cut -c $i) rev=$rev$temp done echo $rev ------------------------------------------------------------------------------------------- 9.Write a shell script to reverse the list of strings and reverse each string further in the list. > #!/bin/bash echo 'Enter array of Strings : ' read -a arr min=0 max=`expr ${#arr[@]} - 1` x=$max while (( $min <= $max )) do newArr[$min]=${arr[$max]} newArr[$max]=${arr[$min]} (( min++ )) (( max-- )) done max=$x for (( i=0; i<=max; i++ )) do rev="" str=${newArr[$i]} let "len=${#str} -1" for (( j=$len; j>=0; j-- )) do rev="$rev${str:$j:1}" done newArr[$i]=$rev done echo ${newArr[@]} --------------------------------------------------------------------------------------- 10. Write a shell script to print the reverse of an input number. > #!/bin/bash echo 'Enter a number : ' read num n=$num sum=0 rem=0 while (( $n > 0 )) do rem=`expr $n % 10` sum=`expr $sum \* 10` sum=`expr $sum + $rem` n=`expr $n / 10` done echo 'Reverse : ' $sum --------------------------------------------------------------------------------------- |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |