Operating Systems Laboratory - A virus
test banner

Post Top Ad

Responsive Ads Here

Operating Systems Laboratory

Share This
  • Operating Systems Laboratory 

  • Practical 1

    Installation Process of various Operating Systems. 
    operating system - OS
    The operating system (OS) is the most important program that runs on a computer. Every general-purpose computer must have an operating system to run other programs and applications.
    Classification of Operating systems
    Multi-user: Allows two or more users to run programs at the same time. Some operating systems permit hundreds or even thousands of concurrent users.
    Multiprocessing : Supports running a program on more than one CPU.
    Multitasking : Allows more than one program to run concurrently.
    Multithreading : Allows different parts of a single program to run concurrently.
    Real time: Responds to input instantly. General-purpose operating systems, such as DOS and UNIX, are not real-time.

    Popular Operating Systems
    The three most popular types of operating systems for personal and business computing include Linux, Windows and Mac.
    Linux Operating Systems
    Linux is a freely distributed open source operating system that runs on a number of hardware platforms. The Linux kernel was developed mainly by Linus Torvalds and it is based on Unix.
    Mac Operating Systems
    Mac OS is the official name of the Apple Macintosh operating system. Mac OS features a graphical user interface (GUI) that utilizes windows, icons, and all applications that run on a Macintosh computer have a similar user interface.
    Windows Operating Systems
    Microsoft Windows is a family of operating systems for personal and business computers. Windows dominates the personal computer world, offering a graphical user interface (GUI), virtual memory management, multitasking, and support for many peripheral devices.
  • Practical 3
    • Execute various basic Linux commands, commands for files and directories, creating and viewing files, File comparisons, Disk related commands. 

    The traditional UNIX environment is a CLI (Command Line Interface), where you type commands to tell the computer what to do. It is fast and powerful but to use it, you need to know few basic commands. Terminal is the command-line interface in various Linux distributions.
    Starting Terminal:
    • The easiest way to launch terminal is use of search function in the dashboard. You can go like Dash -> Search for terminal
    • Or you can use the shortcutCtrl + Alt + T
    Commands
    The Manual
    man: This command brings up the manual of the Linux commands. The man pages are by default built into most Linux distributions.
    For example: man cp: This will bring up the manual of the cp command.
    Likewise, any command's manual can be accessed via this command.
    Listing Contents
    You can view the contents of any directory using the ls command which returns a list of the files and sub-directories in a directory. In Linux, directory is synonymous to folders in MS Windows.
    The ls command can be issued with some optional parameters like:
    • ls -a: This lists hidden files in the listing of contents of the directory.
    • ls -l: This displays attributes like permissions, timestamp, user who created the corresponding file or directory in the results returned.
    Changing directory
    By default, when you start a terminal session, you are in the home directory. To change your working directory, you use the cd command. To do this, type cd followed by the pathname of the desired working directory. The example below changes into the Documents directory.
    cd Documents
    If you need to move back a directory (parent directory), you can use the below command. For example, if you were in the Documents directory when you typed this command, it would move you back into the home directory.
    cd ..
    If you were in more than one directory (e.g. Document/test) and wanted to move back to the home directory, you could use any of the below commands.
    cd ~ cd
    Make Directory
    Short for make directorymkdir is used to create directories on a file system. If the specified DIRECTORY does not already exist, mkdir creates it. The example below shows creation of a directory called test.
    mkdir test
    Dealing with files
    The command below creates an empty file.
    touch sample.txt
    The next command allows you to add content to a file in the terminal only. Type:
    cat > sample.txt
    After pressing Enter, you are not returned to the prompt. Instead, the cursor is placed on the next line, allowing you to enter text into your file. Type your lines of text, pressing Enter after each one. When you are done, press Ctrl + D to exit the file and return to the prompt.
    The next command is useful if you have to append content to an existing file. Using the previous command again will replace the existing contents of the file. ">>" is for append and ">" is used if you add content to a file for the first time or you wish to replace the previous content.
    cat >> sample.txt
    You can use editors like gedit, vi or vim to edit file. Specify the name of the file with the editor command and start editing. For example the next command creates a file and opens it in vi editor. Details of using vi editor will be discussed in the next practical. You can use another editor as well.
    vi sample.txt
    If you want to view the contents of a file, type the command below:
    cat sample.txt
    If a document is too large and you use cat command, you will be presented with the end of the file's contents in the terminal session. However, if you choose to scroll with down arrow, use the command below:
    more sample.txt
    Deleting Files
    You can delete a file using rm command like:
    rm sample.txt
    Or two files with specific names can be deleted like:
    rm sample1.txt sample2.txt
    If you want to delete all text files for an instance (note the files with same extension), you can use wildcards like:
    rm *.txt
    The command above will delete all the text files in the current working directory. Some other alterations of wildcards can be:
    rm sample. rm .*
    Try these and more yourself and see the magic happening!
    Deleting Directories
    rmdir sampledir
    This command deletes the empty directory sampledir. If you want to delete a subdirectory in the current working directory, type:
    rmdir sampledir/test
    In case a file is not empty, use:
    rm -r sampledir
    All the files and sub-directories will be deleted as well with the parent directory sampledir.
    Cut/Copy & Paste
    The cp program copies files and directories. In its simplest form, it copies a single file:
    cp file1 file2
    file1 is the source file i.e. the one being copied and file2 is the destination. Further, if you want to copy the contents of file1 (into a file named file1) inside of directory sampledir, you can by:
    cp file1 sampledir
    Multiple files can also be copied in a directory using:
    cp file1 file2 file3 file4 sampledir
    All the four files will be copied inside the sampledir.
    The mv command performs two different functions depending on how it is used. It will either move one or more files to a different directory, or it will rename a file or directory. To rename a file, it is used like this:
    mv filename1 filename2
    To move files to a different directory:
    mv file1 file2 file3 directory
    Some Other Commands
    pwd - prints the current working directory history - prints the history of commands uname - returns the name of operating system whoami - returns the user currently using the system
    File Comparison
    The diff command compares two files and returns result illustrating the differences in the two files being compared. For example:
    diff file1 file2
    The first line of the diff output will contain:
    • line numbers corresponding to the first file
    • a letter (a for add, c for change, or d for delete)
    • line numbers corresponding to the second file
    Lines preceded by a < are lines from the first file and those preceded by > are lines from the second file. The three dashes (- - -) merely separate the lines of file1 and file2.
    Disk Related Commands
    fdisk is the most commonly used command to check the partitions on a disk. The fdisk command can display the partitions and details like file system type. However it does not report the size of each partitions. Type:
    fdisk -l
    sfdisk is another utility with a purpose similar to fdisk, but with more features. It can display the size of each partition in MB. Simply type:
    sfdisk
    df prints out details about only mounted file systems. The list generated by df even includes file systems that are not real disk partitions. It can be used like:
    df df -h
    The option -h is used for the results to displayed in human-readable format. If not used, you get results of size in the form of large numbers. Sizes are displayed in Kbs or Mbs if this flag is used.
    Only the file systems that start with a /dev are actual devices or partitions. You can use grep to filter out real hard disk partitions/file systems like:
    df -h | grep ^/dev
    More details on different options can be checked here: http://www.tecmint.com/how-to-check-disk-space-in-linux/
    du is a standard Unix/Linux command, used to check the information of disk usage of files and directories on a machine. The du command has many parameter options that can be used to get the results in many formats. The du command also displays the files and directory sizes in a recursively manner. It can be used similarly like df:
    du du -h
    More details on its options can be checked here: http://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/
    lsblk lists out all the storage blocks, which includes disk partitions and optical drives. Details include the total size of the partition/block and the mount point if any. Does not report the used/free disk space on the partitions. It is also simple to use:
    lsblk
    blkid prints the block device (partitions and storage media) attributes like uuid and file system type and does not report the space on the partitions. Type:
    blkid
    hwinfo is a general purpose hardware information tool and can be used to print out the disk and partition list. The output however does not print details about each partition like the above commands. You might have to install it before using it:
    sudo apt-get install hwinfo
    Note: For any of the commands mentioned in this practical, details can be checked using the mancommand to explore more details and options for the command under query.
    • Practical 4

      Execute Linux commands for Processes in Linux, connecting processes with pipes, background processes, managing multiple processes.

      A running instance of a program is called a process. Say you have two terminal windows showing on your screen, which implies you are running the terminal twice and hence you have two terminalprocesses. Each terminal window is running a shell which is further a process.
      Even when you sit down on your computer, there are processes running. Each program running has several processes associated to it. Each process running has its unique process ID also referred as pid. If you invoke a program several times, a different process ID is assigned to each new instance running.

      Viewing active processes

      The ps command displays the processes that are running on your system. By default, invoking psdisplays the processes controlled by the terminal or terminal window in which ps is invoked. For example:
      ps
      PID           TTY        TIME        CMD
      21693        pts/8      00:00:00     bash
      21694        pts/8      00:00:00     ps
      
      The first process bash is the shell running on this terminal and the second is the instance of the psitself. The -e option instructs ps to display all processes running on the system.
      To know all the processes and correspondingly their assigned pid, run:
      ps -A
      

      Piping

      There may be too many processes to read at one time and so you can pipe out the output usingless command and scroll at your own pace. Type:
      ps -A | less
      
      Press q to exit.
      What the pipe operator does is feed the output from the program on the left as input to the program on the right.
      You could also pipe the output through grep to search for a specific process without using any other commands. The following command would search for the firefox process and return its PID in the result:
      ps -A | grep firefox
      
      Some more examples of piping can be:
      ls | head -3
      ls | head -3 | tail -1
      
      In the first command above, we list only the first three files (via use of head) in the current working directory. The latter statement outputs only the third file in the directory by inputting results ofhead to the tail command.

      Monitoring processes

      Top command is a performance monitoring program used frequently by many system administrators to monitor Linux performance. It displays all the running and active real-time processes in ordered list and updates it regularly. It displays:
      • CPU usage
      • Memory usage
      • Swap Memory
      • Cache Size
      • Buffer Size
      • Process PID
      • User
      • Commands and much more.
      It also shows high memory and cpu utilization of a running processes. The top command is much useful for system administrator to monitor and take correct action when required. To run the command, simply type
      top
      
      Htop is a much advanced interactive and real time Linux process monitoring tool. This is much similar to Linux top command but it has some rich features like user friendly interface to manage process, shortcut keys, vertical and horizontal view of the processes and much more. It is a third party tool and is not included in Linux systems. To install it, type:
      sudo apt-get install htop
      
      And to run it, type:
      htop
      
      and check the results.
      pgrep returns the process IDs that match a given a search term. For example, you could use the following command to find Firefox’s PID:
      pgrep firefox
      

      Killing a process

      You can kill a running process with the kill command. Simply specify on the command line the process ID of the process to be killed. The command below kills the process with PID 2534
      kill 2534
      
      The pkill and killall commands can kill a process, given its name. Use either command to kill Firefox:
      pkill firefox
      killall firefox
      

      Nice & Renice

      With the help of nice command, you can set the priority of a process. If you give a process a higher priority, then Kernel will allocate more cpu time to that process.
      By default when a program is launched in Linux, it gets launched with the priority of 0. However you can change the priority of your program by any of the following methods:
      • You can launch a program with your required priority.
      • Or you can also change the priority of an already running process.
      The first is achieved using the nice command. The column NI in the output of the top command is the nice value i.e. the priority of the process. Most of the processes will have priority of 0 as mentioned earlier. The range of the nice priority values is -20 to 19. The syntax of the nice command is:
      nice -n process_name
      
      A nice value of numerically higher number is low on priority and a nice value of numerically low number is higher on priority. The following commands will do the same thing:
      nice -10 process_name
      nice -n 10 process_name
      
      i.e. assign priority 10 to the process whose name is mentioned in the command as process_name.
      In order to assign a negative priority to a process, type:
      nice --n process_name
      
      where n is the number and note the double - - in the command.
      In order to change the priority of an already running process, we use renice command. The renice command requires a PID. The following command makes a process run with very low priority:
      renice 19 PID
      
      The last two portions of this practical which include background processes and managing of multiple processes is discussed proficiently here: https://chrisjean.com/multitasking-from-the-linux-command-line-plus-process-prioritization. Proceed to this URL for further sections.

      • Practical 5

        • Study and usage of vi editor
        The default editor that comes with the UNIX operating system is called vi (visual editor). It has two modes of operation:
        • Command mode In command mode, you move around the file and perform editing operations such as searching for text, deleting text, changing text, and so on. You usually start in command mode.
        • Insert mode You switch to this mode by use of i once you are in the editor. In insert mode, you type new text into the file at the insertion point. To return to command mode, press the Esc (Escape) key.
        These two modes determine the way the editor behaves. Anything you type in insert mode is considered text to be inserted into the file. If you are trying to type a command and nothing happens, or the character appears under the cursor, then you probably forgot to press Esc to escape from insert mode.

        Starting vi

        You may use vi to open an already existing file by typing
        vi filename
        
        where filename is the name of the existing file. If the file is not in your current directory, you must use the full pathname.
        Or you may create a new file by typing
        vi newname
        
        where newname is the name you wish to give the new file.

        Exiting vi

        You can get out of vi by saving or abandoning your changes, or by restarting from the beginning. If these commands don't seem to work for you, you may be in insert mode. If in doubt, pressing Esc will leave insert mode and return you to command mode where these commands should work.
        :q! Quit editing the file and abandon all changes. This is a very common idiom for getting out of trouble.
        :w! Write the file (whether modified or not). Attempt to overwrite existing files or read-only or other unwritable files. You may give a filename as a parameter, and that file will be written instead of the one your started with. It's generally safer to omit the ! unless you know what you're doing here.
        ZZ or :q Write the file if it has been modified. Then exit. This is a very common idiom for normal vi exit.
        :wq Write the changes and quit the editor. It is combination of :w and :q.

        Entering text

        In order to begin entering text in this empty file, you must change from command mode to insert mode. To do this, type
        i
        
        Nothing appears to change, but you are now in insert mode and can begin typing text. In general, vi's commands do not display on the screen and do not require the Return key to be pressed.
        By default, insertion starts one charcater left to the current cursor position. To append, type:
        a
        
        This makes you enter insert mode after the character at the current position. Type your text and press Esc to return to command mode. Use A to insert at the end of the current line.

        Moving around

        To move the cursor to another position, you must be in command mode. If you have just finished typing text, you are still in insert mode. Go back to command mode by pressing Esc. If you are not sure which mode you are in, press Esc once or twice until you hear a beep. When you hear the beep, you are in command mode.
        The cursor is controlled with four keys: h, j, k, l.
         Key        Cursor Movement
         ---        ---------------
         h        left one space
         j        down one line
         k        up one line
         l        right one space
         w        next word on the current line
         e        next end of word on the current line
         b        previous beginning of the word on the current line
        

        Deleting Characters

        To delete a character from a file, move the cursor until it is on the incorrect letter, then type
          x
        
        The character under the cursor disappears. To remove four characters (the one under the cursor and the next three) type
         4x
        
        To delete the character before the cursor, type
          X (uppercase)
        

        Deleting Words

        To delete a word, move the cursor to the first letter of the word, and type
          dw
        
        This command deletes the word and the space following it.
        To delete three words type
           3dw
        

        Deleting Lines

        To delete a whole line, type
           dd
        
        The cursor does not have to be at the beginning of the line. Typing dd deletes the entire line containing the cursor and places the cursor at the start of the next line. To delete two lines, type
           2dd
        
        To delete from the cursor position to the end of the line, type
           D (uppercase)
        

        Searching text

        You can search for text in your file using regular expressions:
        /
        
        Use / followed by a regular expression or a string to search forward in your file.
        ?
        
        Use ? followed by a regular expression or a string to search backward in your file.
        n
        
        Use n to repeat the last search in either direction.
        You may precede any of the above search commands with a number indicating a repetition count. So 3/x will find the third occurrence of x from the current point, as will /x followed by 2n. Similarly, 2/^e will find the second line from the current position that starts with e.

        Undo changes

        Perhaps the most important command is the one that allows you to back up and undo your last action. Unfortunately, this command acts like a toggle, undoing and redoing your most recent action. You cannot go back more than one step. To use it, type:
        u
        

        Copy and paste

        The command Y or yy copies (yanks) one or more lines. To copy one line, two lines, 10 lines, and all lines to the end of the file, respectively:
        Y 2Y
        10Y
        yG
        
        To paste the text contained in the buffer above (uppercase P) or below the current cursor position (lowercase p), respectively:
        P p
        
        This is the end of this practical. If you are interested more, you can look at various online resources.

        Practical 6
        • Basics of Shell programming, various types of shell, Shell Programming in bash. 
        What is a shell?
        In computing, a shell is a user interface for access to an operating system's services. In general, operating system shells use either a command-line interface (CLI) or graphical user interface (GUI), depending on a computer's role and particular operation. It is named a shell because it is a layer around the operating system kernel.
        Basics of Shell Programming
        1. To get a Linux shell, you need to start a terminal.
        2. To see what shell you have, run: echo $SHELL.
        3. In Linux, the dollar sign ($) stands for a shell variable.
        4. The echo command just returns whatever you type in.
        5. The pipeline instruction (|) comes to rescue, when chaining several commands.
        6. Linux commands have their own syntax, Linux won’t forgive you whatsoever is the mistakes. If you get a command wrong, you won’t flunk or damage anything, but it won’t work.
        7. #!/bin/sh – It is called shebang. It is written at the top of a shell script and it passes the instruction to the program /bin/sh.
        Types of Shell
        Bourne Shell
        The original Bourne shell is named after its developer at Bell LabsSteve Bourne. It was the first shell used for the Unix operating system, and it has been largely surpassed in functionality by many of the more recent shells. However, all Unix and many Linux versions allow users to switch to the original Bourne Shell, known simply as sh, if they choose to forgo features such as file name completion and command histories that later shells have added.

        C Shell
        The C shell, as its name might imply, was designed to allow users to write shell script programs using a syntax very similar to that of the C programming language. It is known as csh.

        TC Shell
        TC shell is an expansion upon the C shell. It has all the same features, but adds the ability to use keystrokes from the Emacs word processor program to edit text on the command line. For example, users can press Esc-D to delete the rest of the highlighted word. It is also known as tcsh.

        Korn Shell
        Korn Shell was also written by a developer at Bell LabsDavid Korn. It attempts to merge the features of the C shell, TC shell and Bourne shell under one package. It also includes the ability for developers to create new shell commands as the need arises. It is known as ksh.

        Bourne-Again Shell
        The Bourne-Again shell is an updated version of the original Bourne shell that was created by the Free Software Foundation for its open source GNU project. For this reason, it is a widely used shell in the open source community.
        Its syntax is similar to that used by the Bourne shell, however it incorporates some of the more advanced features found in the C, TC and Korn shells.
        Among the added features that Bourne lacked are the ability to complete file names by pressing the TAB key, the ability to remember a history of recent commands and the ability to run multiple programs in the background at once. It is known as bash.
        Shell programming in bash
        Bash is an interactive shell. You type in commands. Bash executes them. As a shell, it is available via Terminal. At the same time, bash is also a scripting language. Bash scripts can automate routine or otherwise arduous tasks involved in systems administration.
        A shell script is little more than a list of commands that are run in sequence. Conventionally, a shellscript should start with a line such as the following:
        #!/bin/bash
        
        
        This indicates that the script should be run in the bash shell regardless of which interactive shell the user has chosen. This is very important, since the syntax of different shells can vary greatly.
        Traditional hello world script
        !/bin/bash
        # My first bash script       
        echo "Hello World "
        
        
        This script has only three lines. The first indicates the system which program to use to run the file. The second line is a comment. Anything starting with # is a comment in bash. Next the only action performed by this script is in third line which prints Hello World on the terminal when the script is run.
        You have to change the permissions of your script to make it executable. To do so, type the following command in terminal:
        chmod u+x scriptname
        
        
        To execute the script from the current directory, you can run:
        ./scriptname
        
        
        When the shell executes a script, it finds the #!/path/to/interpreter. It then runs the interpreter (in this case, /bin/bash) on the file itself.
        This was all about getting started with programming in bash. In the next practical, we will learn creating variables and using them.

        Practical 7
         Study and implementation of shell variables, shell keywords.
        Shell variables
        Variables are words that hold a value. The shell enables you to create, assign, and delete variables. You define a variable as follows:
        name=value
        
        
        where name is the name of the variable and value is the value of the variable. An example of variable definition is:
        a=hello
        
        
        and refer to it as follows:
        $a
        
        
        More specifically, $a is used to denote the value of the variable a. Some things to take note of regarding semantics:
        • Bash gets unhappy if you leave a space on either side of the = sign. For example, the following gives an error message:
        • X = hello
          
          
        • While I have quotes in my example, they are not always necessary. where you need quotes is when your variable names include spaces. For example,
        X=hello world # error
        X="hello world" # OK
        
        
        This is because the shell essentially sees the command line as a pile of commands and command arguments separated by spaces.
        Variable Names
        The name of a variable can contain only:
        • letters (a to z or A to Z)
        • numbers ( 0 to 9) or
        • the underscore character ( _ ).
        In addition, a variable's name can start only with a letter or an underscore. The following examples are valid variable names:
        _FRUIT 
        FRUIT_BASKET 
        TRUST_NO_1 
        TWO_TIMES_2
        
        
        but
        2_TIMES_2_EQUALS_4
        
        
        is not a valid variable name. To make this a valid name, add an underscore at the beginning of its name:
        _2_TIMES_2
        
        
        Further variable names such as 1 or 11 or any of the numbers are reserved for special use by the shell. Also other special characters like ! or * or - have special meaning in the shell. Use of any of these characters is bound to confuse the shell. The following variable names are invalid:
        FRUIT-BASKET 
        _2*2 
        TRUST_NO_1!
        
        
        Unsetting variables
        Unsetting a variable tells the shell to remove the variable from the list of variables that it tracks. This is like asking the shell to forget a piece of information because it is no longer required. The command can be used as:
        unset name
        
        
        where name is the name of the variable that you want to unset.
        Shell keywords
        Different keywords in shell are listed in alphabetical order below:
        • alias, awk
        • bg
        • cat, cd, chmod, chsh, cp, cut
        • echo, expr
        • fg, file, find
        • grep
        • history
        • jobs
        • kill
        • less, locate, logout, lpq, lpr, lprm, ls
        • man, mkdir, more, mv
        • ps, pwd
        • rm, rmdir
        • scp, sleep, sort, ssh
        • tar, touch, tty
        • uniq
        • whereis, which, who
        These are all the keywords that find use in shell scripting. Write 1-2 sentences for each in your practical file.


        • Practical 8

          Practical 8
          •  Implement conditional statements, looping statement and case statement in Shell programming.
          Note: In this practical, the syntax of various statements has been given. The TO-DO parts of this practical imply that you have to write the corresponding script and paste respective screenshot in your practical file.
          Conditional Statement
          The order in which commands execute in a shell script is called the flow of the script. The ifstatement is normally used for conditional execution of commands.
          The if statement performs actions depending on whether a given condition is true or false. The basic if statement syntax follows:
          if condition1
          then
              statement1
              statement2
              and so on 
          elif condition2 
          then 
              statements here
          else 
              statements here 
          fi
          
          
          The elif and else statements are optional.
          TO-DO: Check if a number input by the user is even or odd.
          Looping statement
          The for loop repeats a set of commands for every item in a list. The basic syntax of this loop is:
          for name in word1 word2 ... wordN
          do 
              list 
          done
          
          
          Note: You can also use brace expansion for word1 ... wordN.
          Here name is the name of a variable and word1 to wordN are sequences of characters separated by spaces (words). Each time the for loop executes, the value of the variable name is set to the next word in the list of words, word1 to wordN. The first time, name is set to word1, the second time, it's set to word2, and so on.
          TO-DO: Use the loop structure for printing table of a number.
          Case statement
          The case statement is the other major form of flow control available in the shell. In this section I explain its usage. The basic syntax is:
          case word in 
          pattern1) 
              statements here 
                  ;;
          pattern2) 
              statements here 
                  ;;
          esac
          
          
          Here the string word is compared against every pattern until a match is found. The statements following the matching pattern are executed. If no matches are found, the case statement exits without performing any action.
          When a list executes, the command ;; indicates that program flow should jump to the end of the entire case statement. This is similar to break in the C programming language.
          TO-DO: Create a calculator that performs various arithmetic operations like: +-, , /%.*
          This is the end of this practical.

          • Practical 9


            Practical 9
            •  Implement parameter passing and arguments in Shell programming.
            The general format for the invocation of programs in UNIX is:
            command options files
            
            
            Here command is the command name, options is any option that you need to specify, and files is an optional list of files on which the command should operate. Consider the following example:
            ls -l *.doc
            
            
            Here ls is the command, -l is the only option, and .doc is the list of files for ls* to operate on.
            Some special variables
            $0 The name of the command being executed.
            ------------------------------------------------------------
            $n These variables correspond to arguments with which script  
               was invoked. n is a +ve decimal number corresponding to    
               the position of the argument. Also referred to as 
               positional parameters.
            ------------------------------------------------------------
             $# The number of arguments supplied to a script.
            ------------------------------------------------------------
            $* All the arguments are double quoted.
            ------------------------------------------------------------ 
            $@ All the arguments are individually double quoted.
            ------------------------------------------------------------
            $? The exit status of the last command executed.
            ------------------------------------------------------------
            $$ The process number of the current shell.
            ------------------------------------------------------------
            $! The process number of the last background command.
            
            
            The difference between the options and arguments is subtle. A command's arguments are all of the separate strings or words that appear on the command line after the command name, whereas options are only those arguments that change the behavior of the command. For example:
            ls -a fruit
            
            
            the command is ls and its arguments are -a and fruit. The option to the ls command is -a.
            Say you have a script file named myscript.sh that performs addition of two arguments passed to it. This will be executed as:
            ./myscript.sh 3 4
            
            
            Here the first argument i.e. 3 is referred to as \$1 in the script and the second argument is referred to as \$2.
            TO-DO: 1.Write a script that performs addition on an unspecified number of integers passed as arguments by the user. Modify the code to add a number to the sum only if the number is greater than 10. 2. Write a shell script takes the name a path (eg: /home/andrew/course/15/123/demo), and counts all the sub directories (recursively). 3. Write a shell script that compares the files in two directories and lists which files in the first directory are missing from the second.

            • Practical 10

              Practical 10
              • Implement Shell programs for automate system tasks and report printing.
              This practical is based on the learnings from previous practicals and hence include only the TO-DOs.
              TO-DO: 1. Create a file named employee.txt which has the content similar to the following data entry, which will be used further.
              emp_id emp_name emp_designation emp_department emp_salary
              100    Thomas   Manager         Sales          $7,000
              
              
              Next perform the following two operations on your database: (a) Print the list of employees in a given department (say technology or sales, any in your data. Also print the total number (count) of employees in the department. (b) Print the number of employees having salary greater than a specified value. Set that value yourself.
              2. Write a simple script to create a backup file for all the directories in any given directory of your system (can be your home or documents or downloads, anyone in your system).

            No comments:

            Post a Comment

            Post Bottom Ad

            Responsive Ads Here

            Pages