Preview

Shell Programming

Good Essays
Open Document
Open Document
1869 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Shell Programming
1) Shell Program To check the greater number between two numbers
#!/bin/sh
[sourcecode language='sh'] echo Enter a Number read num1 echo Enter Number read num2 if test $num1 -ge $num2 then echo $num1 is greater than $num2 else echo $num2 is greater than $num1 fi 2) Shell Program to Check a number is even or odd
[sourcecode language='sh'] echo Enter a Number to Find Even or odd read num b=`expr $num % 2` if [ $b -eq 0 ] then echo Even number else echo Odd Number fi 3) Shell Program to check whether a year is leap or Not
[sourcecode language='sh'] echo Enter the year to check for Leap read year leap=`expr $year % 4` check1=`expr $year % 100` if [ $check1 -eq 0 ] then check2=`expr $year % 400 | bc` if [ $check2 -eq 0 ] then echo Leap else echo Not Leap fi break; fi if [ $leap -eq 0 -a $check1 -ne 0 ] then echo Leap fi 4) Shell Program to Find a File exists in the present working directory echo Enter a File Name read filename if [ -s $filename ] then if [ -f $filename ] then echo File Exists… else echo Directory Exists… fi ls $filename -n else echo Not found fi [/sourcecode]
5) Shell Program To copy a file into another file echo Enter Source File Name Destination File name read srcfile destfile cp $srcfile $destfile echo Copy Complete… echo $destfile “Is a Copy of ” $srcfile

6) How to write shell script that will add two nos, which are supplied as command line argument, and if this two nos are not given show error and its usage

if [ $# -ne 2 ] then echo "Usage - $0 x y" echo " Where x and y are two nos for which I will print sum" exit 1 fi echo "Sum of $1 and $2 is `expr $1 + $2`"

7) Write Script to find out biggest number from given three nos. Nos are supplies as command line argument. Print error if sufficient arguments are not supplied.
# Algo:
# 1) START: Take three nos as n1,n2,n3.
# 2) Is n1 is greater than n2 and n3, if yes
#

You May Also Find These Documents Helpful

  • Satisfactory Essays

    = z) return true; else return false; } Problem 5 a. Output: 720 b. Output: 0 c. Output: 71 d. Output: 362880 Problem 6 a. Output: “Take Programming I.” b. Output:…

    • 188 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    PT1420 Chapter 3 Review

    • 1062 Words
    • 8 Pages

    6. Write a pseudocode statement that declares the variable total so it can hold integers. Initialize the variable with the value 0.…

    • 1062 Words
    • 8 Pages
    Satisfactory Essays
  • Good Essays

    Nt1330 Unit 4

    • 1313 Words
    • 6 Pages

    Refer to the exhibit. What three conclusions can be determined based on the exhibited commands? (Choose three.)…

    • 1313 Words
    • 6 Pages
    Good Essays
  • Better Essays

    Nt1310 Unit 4

    • 3614 Words
    • 15 Pages

    13. If the following program (myprog) is run from the command line as myprog monday tuesday wednesday thursday? What would be the output?…

    • 3614 Words
    • 15 Pages
    Better Essays
  • Satisfactory Essays

    4.) Write assignment statements that perform the following operations with the variables a, b, and c:…

    • 453 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Homework Unit 3

    • 354 Words
    • 2 Pages

    3. Multiple alternative decision structure- Tests the value of a variable to determine which statements to execute.…

    • 354 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Unit 7 Assignment 1

    • 261 Words
    • 2 Pages

    2. A pretest loop is a loop tests the conditions before performing the iteration. A posttest loop performs the iteration then test the condition.…

    • 261 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    IT210 R5 Appendix D 2

    • 197 Words
    • 2 Pages

    I. Running a program using various sets of inputs to determine if the program is running properly…

    • 197 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Pt1420 Unit 7 Study Guide

    • 582 Words
    • 3 Pages

    21. Write a program that prompts the user to enter two unsigned numbers 0 to FFFFh and their sum in hex on the next line.…

    • 582 Words
    • 3 Pages
    Satisfactory Essays
  • Powerful Essays

    Mat 540 Week 4 Paper

    • 1775 Words
    • 8 Pages

    * Provide a set of values that will test the normal operation of this program segment. Defend your choices.…

    • 1775 Words
    • 8 Pages
    Powerful Essays
  • Satisfactory Essays

    Unit 2 lab 1

    • 636 Words
    • 4 Pages

    1. try giving the following commands and observe the behavior with each combination of options and arguments.…

    • 636 Words
    • 4 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Comp230 W2 Ilab

    • 1120 Words
    • 5 Pages

    Student Name | | Class | Comp230 | Date | 5/16/2013 | VBScript IPO VBox Lab Report ' VBScript: NameAge.vbs ' Written by: ' Date: 5/16/2013 ' Class: Comp230 ' Professor: Giao Dau ' = == == == ==…

    • 1120 Words
    • 5 Pages
    Satisfactory Essays
  • Satisfactory Essays

    UNIT 2

    • 470 Words
    • 3 Pages

    4.) Write assignment statements that perform the following operations with the variables a, b, and c:…

    • 470 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    code program

    • 317 Words
    • 2 Pages

    (Compilation screenshot) - Insert here a screenshot of the result of compiling the above source code: NetBeans IDE 7.3.1 compiles but it did not go to the screen so I could see it, this is why I sent you a message yesterday to let you know this. But the program did run without any problems.…

    • 317 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Concept Programing

    • 443 Words
    • 3 Pages

    1) n > 0 and count = n => count > 0 before the while loop…

    • 443 Words
    • 3 Pages
    Good Essays

Related Topics