Shell script program 2

scmuser created the topic: Shell script program 2

Use a script to take two numbers as arguments and output their sum using (i) bc (ii) expr. include error – checking to test whether two arguments were entered?

tpatil replied the topic: Re: Shell script program 2
If I understand correctly your question, You want to pass 2 parameters to shell script and print the sum of those. Also, you want to throw error if the number of parametrs are less than 2.

#!/bin/bash

if [ $# -lt 2 ]
then
echo "Usage: $0 arg1 arg2"
exit
fi

echo "\$1=$1"
echo "\$2=$2"

let add=$1+$2
let sub=$1-$2

echo -e "Addition=$add\nSubtraction=$sub\n"

Hope this helps…

renjith replied the topic: Re: Shell script program 2
#!/bin/ksh

while echo ” Enter two numbers :\n ” ; do
echo “Enter num 1: “; read A;
echo “Enter num 2: “; read B;
if [ -z $A -o -z $B ] ;then
echo ” Invalid input , pls enter again”
else
break
fi
done

export A B

echo ” ************* MENU *********** \n”
echo ” 1. cal using bc “;
echo ” 2. cal using expr”;
echo ” enter you choice :”;
read c;

case $c in
1) sum=`echo ” $A + $B “|bc` ;;
2) sum=`expr $A + $B` ;;
*) echo “invalid option , run script again”
esac

if [ $? -eq 0 ]
then echo ” Sum is $sum”
else
echo ” Script failed ”
fi

Tagged :

Test your Shell Scripting Skills: – Program 7

scmuser created the topic: Test your Shell Scripting Skills: – Program 7

You are moving files to handled which accepts only 8+3 type filesname. Produce a list of those files in your current directory that fail in this test.

Tagged :

Test your Shell Scripting Skills: – Program 8

scmuser created the topic: Test your Shell Scripting Skills: – Program 8

Write a script that displays a special listing showing the (i) permission (ii) size (iii) filename (iv) last modification time (v) last access time of filenames supplied as arguments. Provide suitable headers using the printf command.

Tagged :

Test your Shell Scripting Skills: – Program 9

scmuser created the topic: Test your Shell Scripting Skills: – Program 9

Find out the pathname of the Korn shell on your machine and then change the interpreter line in all shell script in the current directory that show a different pathname for ksh

Tagged :

Test your Shell Scripting Skills: – Program 10

scmuser created the topic: Test your Shell Scripting Skills: – Program 10

Add the statement #inlclude at the beginning of every C source file in the current directory containing printf or fprintf, if it does not already have it included.

Tagged :

Test your Shell Scripting Skills: – Program 11

scmuser created the topic: Test your Shell Scripting Skills: – Program 11

Write a script that compares two direcotries bar1 and bar2 (supplied as arguments) and copies or overwrites to bar1 from bar2 every file that is (i) not present in bar1 or (ii) newer than its namespace in bar1. (HINT: Use the find command)

Tagged :

Test your Shell Scripting Skills: – Program 12

scmuser created the topic: Test your Shell Scripting Skills: – Program 12

You have a number of C programs that certain comment lines at the beginning of each program. The lines begin with /* followed by the first line of comment, butthe terminator line has */ as the only characters in the line. Remove these comments from all files.

Tagged :

Test your Shell Scripting Skills: – Program 13

scmuser created the topic: Test your Shell Scripting Skills: – Program 13

Write a shell script that uses find to look for a file and echo a suitable message if the file is not found. you must not store the find output in a file.

Tagged :

Test your Shell Scripting Skills: – Program 14

scmuser created the topic: Test your Shell Scripting Skills: – Program 14
Devise a script that allows a user to view, add, delete or modify a setting in a configuration file that contains these setttings in the form variable = value

Tagged :