u-assign1

Embed Size (px)

Citation preview

  • 8/11/2019 u-assign1

    1/3

    ITU UNIX Operating SystemAssignment #1

    Practice creating and using Basic Scripts

    1. A shell is !th a c!mmand line interpreter and a pr!gramminglanguage. "plain the di$$erence et%een the $!ll!%ing shells&

    bash cshperl ksh

    In y!ur h!me direct!ry' ma(e a in sudirect!ry )i$ it d!esn*t eist+

    mkdir bin

    ,! int! that sudirect!ry cd bin

    -. In y!ur in sudirect!ry' create the $!ll!%ing $ile named commandsusing "macs !r i )!r any tet edit!r+

    # a simple shell scriptcaldatewho

    /. Sae the $ile' 0eae the edit!r' try t! run the script commandshat happens2

    3. 4a(e the script eecutale chmod ug+x commands

    5. N!% try t! run the script commands

    6. 4a(e sure the ash shell is al%ays eecuted %hen y!u run thisscript

    ,! ac( int! the "dit!r and add this statement t! the t!p !$ the $ile

    #!/bin/bash

    POSITIONA0 PA7A4"T"7S

    hen y!u call a shell script %ith arguments' y!u can access them insidethe script %ith the special ariales

    $1, $2,etc.. $*re$ers t! all !$ the arguments

  • 8/11/2019 u-assign1

    2/3

    The ariale $0re$ers t! the name !$ the calling pr!gram !r script.

    8. 9reate the $!ll!%ing script called echoargs

    #!/bin/bash# illustrate the use o positional parametersecho $0 $1 $2 $" $ $ $% $& $' $(

    :. 4a(e the script eecutale and try it !ut %ith this c!mmand& echoargs )o be or not to be

    ;. 9hange the script s! it l!!(s li(e this&

    #!/bin/bash# illustrate the use o positional parameters, user deined# ariables and the read commandecho what is our name-read nameecho .well, $name, ou tped $# arguments.echo .$*.

    1

  • 8/11/2019 u-assign1

    3/3

    echo .a $1.echo .ate $" $2 $%.

    15. Sae the $ile' ma(e it eecutale' run the $ile

    APP0I9ATION&

    The %c )?%!rd c!unt?+ $ilters and c!unts the %!rds' lines' and charactersin a $ile. @!r eample' try running %c !n the setdate $ile y!u ust made&

    $ wc setdate% 2" 12 setdate

    )& %hat p!siti!nal parameter is the $ilename in the !utput2+

    The !utput tells us there are 6 lines' -/ %!rds and 1-3 characters. T!

    impr!e !n %c' y!u are g!ing t! ma(e a ne% script called mwc' %hich%ill pr!ide a m!di$ied !utput laeling each p!rti!n s! it is m!rereadale. The !utput !$ y!ur script mwc' used in the $!ll!%ingc!mmandmwc setdate sh!uld read

    setdate count3 lines % words 2" characters 12

    T! d! this' create the script mwcusing the $!ll!%ing plan&

    1+ Select the ash shell.-+ 7un %c !n the C1 p!siti!nal parameter and capture the !utput usingset/+ Print the $ilename )C3+3+ Print the numer !$ lines )C1+' numer !$ %!rds )C-+ and numer !$characters )C/+ using appr!priate laels.5+ Use y!ur script setdate as a m!del $!r this pr!lem.6+ Paste y!ur $inished script el!%.