• Welcome to Bashguru

    Linux is one of popular version of UNIX operating System. It is open source as its source code is freely available. It is free to use. Linux was designed considering UNIX compatibility. It's functionality list is quite similar to that of UNIX and become very popular over the last several years. Our Basic motive is to provide latest information about Linux Operating system.

  • Python Programming

    Python is a comparatively simple programming language, compared to c++. Although some of the benefits of c++ are abstracted away in python, they are replaced with an overall easier to learn language with many “intuitive” features. For this reason it is common and recommended by most professionals that people new to programming start with python.

  • Perl Programming

    Perl is an open-source, general-purpose interpreted programming language. Used often for CGI, Perl is also used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications. The Perl languages borrow features from other programming languages including C, shell scripting (sh), AWK, and sed. They provide powerful text processing facilities without the arbitrary data-length limits of many contemporary UNIX command line tools, facilitating easy manipulation of text files.

  • Android

    Android is an operating system based on the Linux kernel, and designed primarily for touch screen mobile devices such as smart phones and tablet computers. Android is a Linux-based software system, and similar to Linux, is free and open source software. This means that other companies can use the Android operating developed by Google and use it in their mobile devices.Android gives you a world-class platform for creating apps and games for Android users everywhere, as well as an open marketplace for distributing to them instantly.

Tuesday, November 24, 2009

Posted by venu k
7 comments | 2:20 PM
Hello friends,
I have watched this video on Youtube.I hope you will also enjoy it.



Original link for this video is http://www.youtube.com/watch?v=bYcF_xX2DE8

Tuesday, November 17, 2009

Posted by venu k
9 comments | 11:58 AM

#!/bin/bash
# SCRIPT: primenumbers.sh
# USAGE : ./primenumbers.sh <Range Value>
# or;
# ./ primenumbers.sh <Start Range Value> <End Range Value>
# PURPOSE: Produce prime numbers within a range lmit.

############### DEFINE FUNCTIONS HERE ##############

Usage()
{
echo "********BAD ARGUMENTS**********"
echo "Usage: scriptname <Range Value >"
echo " or "
echo "Usage: scriptname <Start Range Value> <End Range Value>"
exit 1
}

################# ARGUMENTS CHECKING #################

[ $# -gt 2 -o $# -lt 1 ] && Usage
[ $# -eq 1 ] && Bnum=2 && Enum=$1
[ $# -eq 2 ] && Bnum=$1 Enum=$2 && [ $1 -gt $2 ] && Usage
[ $1 -lt 2 ] && Bnum=2

############### MAIN PROGRAM STARTS HERE #############

count=1

while [ $Bnum -le $Enum ]
do
num=$Bnum
Prime="yes"
i=1

#while [ $i -lt $((num/2)) ]
while [ $((i*i)) -lt $((num-1)) ]
do
let i++
if [ $((num%i)) -eq 0 ] # you can also use `expr $num % $i`
then
Prime="no"
break
fi
done

[ "$Prime" = "yes" ] && printf "%5d " $num && let count++

# count is used to print 10 values in a row

[ $count -eq 11 ] && count=1 && echo
let Bnum++
done
echo

OUTPUT:

$ ./primenumbers.sh 1 350
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197 199 211 223 227 229
233 239 241 251 257 263 269 271 277 281
283 293 307 311 313 317 331 337 347 349

$ ./primenumbers.sh 1900 2500
1901 1907 1913 1931 1933 1949 1951 1973 1979 1987
1993 1997 1999 2003 2011 2017 2027 2029 2039 2053
2063 2069 2081 2083 2087 2089 2099 2111 2113 2129
2131 2137 2141 2143 2153 2161 2179 2203 2207 2213
2221 2237 2239 2243 2251 2267 2269 2273 2281 2287
2293 2297 2309 2311 2333 2339 2341 2347 2351 2357
2371 2377 2381 2383 2389 2393 2399 2411 2417 2423
2437 2441 2447 2459 2467 2473 2477

$ ./primenumbers.sh 200
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197 199

[root@localhost shell]# ./primenumbers.sh 200 100
********BAD ARGUMENTS**********
Usage: scriptname <Range Value>
or
Usage: scriptname <Start Range Value> <End Range Value>

NOTE:
this script can't find the highest prime number,but it can figure out the highest prime number your system is capable of calculating.
Posted by venu k
21 comments | 8:46 AM
Reposted on 18-06-2011 and Method 4 was deleted.

The simplest primality test is as follows: Given an input number n,
check whether any integer m from 2 to n − 1 divides n. If n is divisi-
ble by any m then n is composite, otherwise it is prime.

Method 1:


Now most people who write finding prime number in shell script(Almost
in all languages) may start with something simple, like:

#!/bin/bash
# SCRIPT: prime1.sh
# USAGE : ./prime1.sh
# PURPOSE: Finds whether given number is prime or not
#####################################################################

echo -n "Enter a number: "
read num
i=2

while [ $i -lt $num ]
do
if [ `expr $num % $i` -eq 0 ]
then
echo "$num is not a prime number"
echo "Since it is divisible by $i"
exit
fi
i=`expr $i + 1`
done

echo "$num is a prime number "

Output:
[root@venu ]# ./prime1.sh
Enter a number: 1879
1879 is a prime number
[root@venu ]# ./prime1.sh
Enter a number: 119
119 is not a prime number
Since it is divisible by 7

Using here string you can supply input non interactively.

[root@venu ]# ./prime1.sh <<<2239
Enter a number: 2239 is a prime number

However, rather than testing all m up to n−1, it is only necessary to
test m up to sqrt n: if n is composite then it can be factored into
two values,at least one of which must be less than or equal to sqrt n.

Don't use method 1, it is very worst method, I hope that you will
agree with me at the end of this post.

Method 2a:


#!/bin/bash
# SCRIPT: prime2a.sh
# USAGE : ./prime2a.sh
# PURPOSE: Finds whether given number is prime or not
#####################################################################

echo -n "Enter a number: "
read num

#####################################################################
# Integer Validation #
#####################################################################

# If you are a beginner you can skip this integer validation block.

expr $num + 1 &> /dev/null

if [ $? -ne 0 ]
then
echo "Sorry, You supplied non numerical value"
exit 1
fi

[ $num -lt 2 ] && echo "Values < 2 are not prime numbers" && exit 1

#####################################################################
# Main Script Starts Here #
#####################################################################

i=2
sqrtofnum=`echo "sqrt($num)"|bc`

while [ $i -le $sqrtofnum ]
do
if [ `expr $num % $i` -eq 0 ]
then
echo "$num is not a prime number"
echo "Since it is divisible by $i"
exit
fi
let i++
done

echo "$num is a prime number "

Output:
[root@venu ]# ./prime2a.sh <<<169
Enter a number: 169 is not a prime number
Since it is divisible by 13
[root@venu ]# ./prime2a.sh <<<3181
Enter a number: 3181 is a prime number

Here is same method without using bc command:


Method 2b:


#!/bin/bash
# SCRIPT: prime2b.sh
# USAGE : ./prime2b.sh
# PURPOSE: Finds whether given number is prime or not
#####################################################################

echo -n "Enter a number: "
read num

#####################################################################
# Integer Validation #
#####################################################################

# If you are a beginner you can skip integer validation block.

expr $num + 1 &> /dev/null

if [ $? -ne 0 ]
then
echo "Sorry, You supplied non numerical value"
exit 1
fi

[ $num -lt 2 ] && echo "Values < 2 are not prime numbers" && exit 1

#####################################################################
# Main Script Starts Here #
#####################################################################

i=1
newnum=$((num-1))

while [ $((i*i)) -lt $newnum ]
do
let i++
if [ `expr $num % $i` -eq 0 ]
then
echo "$num is not a prime number"
echo "Since it is divisible by $i"
exit
fi
done

echo "$num is a prime number "

Output:
[root@venu ]# ./prime2b.sh <<<361
Enter a number: 361 is not a prime number
Since it is divisible by 19
[root@venu ]# ./prime2b.sh <<<3571
Enter a number: 3571 is a prime number

Method 3a:


#!/bin/bash
# SCRIPT: prime3a.sh < Number to check >
# USAGE : ./prime3a.sh
# PURPOSE: Finds whether a given number is prime or not.

#####################################################################
# ARGUMENTS CHECKING #
#####################################################################

# If you are a beginner you can skip Arguments checking part.

if [ $# -ne 1 ]
then
echo "Usage: scriptname <number to check>"
exit 1
fi

expr $1 + 1 &> /dev/null

if [ $? -ne 0 ]
then
echo "Sorry, You supplied non numerical value"
exit 1
fi

[ $1 -lt 2 ] && echo "Values < 2 are not prime numbers" && exit 1

#####################################################################
# MAIN PROGRAM STARTS HERE #
#####################################################################

num=$1
sqrtofnum=`echo "sqrt($num)" | bc `
i=2

while [ $i -le $sqrtofnum ]
do
if [ $(((num/i)*i)) -eq $num ]
then
echo "$num is not a prime number"
echo "Since it is divisible by $i"
exit 0
fi

let i++ # you can also use i=`expr $i + 1`
done

echo "$num is a prime number"

Output:
[root@venu ]# ./prime3a.sh 529
529 is not a prime number
Since it is divisible by 23
[root@venu ]# ./prime3a.sh 3571
3571 is a prime number

Here is same method without using bc command:


Method 3b:


#!/bin/bash
# SCRIPT: prime3b.sh
# USAGE : ./prime3b.sh <Number to check >
# PURPOSE: Finds whether a given number is prime or not.

#####################################################################
# ARGUMENTS CHECKING #
#####################################################################

# If you are a beginner you can skip Arguments checking part.

if [ $# -ne 1 ]
then
echo "Usage: scriptname <number to check>"
exit 1
fi

expr $1 + 1 &> /dev/null
if [ $? -ne 0 ]
then
echo "Sorry, You supplied non numerical value"
exit 1
fi

[ $1 -lt 2 ] && echo "Values < 2 are not prime numbers" && exit 1

#####################################################################
# MAIN PROGRAM STARTS HERE #
#####################################################################

num=$1
newnum=$((num-1))
i=1

while [ $((i*i)) -lt $newnum ]
do

let i++ # you can also use i=`expr $i + 1`

if [ $(((num/i)*i)) -eq $num ]
then
echo "$num is not a prime number"
echo "Since it is divisible by $i"
exit 0
fi

done

echo "$num is a prime number"

Output:
[root@venu ]# ./prime3b.sh 12009
12009 is not a prime number
Since it is divisible by 3
[root@venu ]# ./prime3b.sh 16127
16127 is a prime number

Now using time command to test which script runs fast.

OUTPUT 1:
[root@venu ]# time sh prime1.sh <<<99991
Enter a number: 99991 is a prime number

real 5m6.590s
user 1m13.882s
sys 3m29.807s
[root@venu ]# time sh prime2a.sh <<<99991
Enter a number: 99991 is a prime number

real 0m0.558s
user 0m0.159s
sys 0m0.409s
[root@venu ]# time sh prime2b.sh <<<99991
Enter a number: 99991 is a prime number

real 0m0.534s
user 0m0.141s
sys 0m0.405s
[root@venu ]# time sh prime3a.sh 99991
99991 is a prime number

real 0m0.037s
user 0m0.034s
sys 0m0.003s
[root@venu ]# time sh prime3b.sh 99991
99991 is a prime number

real 0m0.041s
user 0m0.034s
sys 0m0.007s

OUTPUT 2:
[root@venu ]# time sh prime1.sh <<<319993
Enter a number: 319993 is a prime number

real 16m44.993s
user 4m3.943s
sys 12m17.365s
[root@venu ]# time sh prime2a.sh <<<319993
Enter a number: 319993 is a prime number

real 0m0.883s
user 0m0.218s
sys 0m0.529s
[root@venu ]# time sh prime2b.sh <<<319993
Enter a number: 319993 is a prime number

real 0m0.739s
user 0m0.238s
sys 0m0.494s
[root@venu ]# time sh prime3a.sh 319993
319993 is a prime number

real 0m0.072s
user 0m0.054s
sys 0m0.007s
[root@venu ]# time sh prime3b.sh 319993
319993 is a prime number

real 0m0.089s
user 0m0.061s
sys 0m0.008s

I hope, now you understood, Just one line of code makes the difference.
Method 1 takes more and more time to find prime number.

Sunday, November 15, 2009

Posted by venu k
127 comments | 1:19 AM

Like UNIX commands, shell scripts also accept arguments from the command line.
They can, therefore, run non interactively and be used with redirection and
pipelines.

Positional Parameters:

Arguments are passed from the command line into a shell program using the
positional parameters $1 through to $9. Each parameter corresponds to the
position of the argument on the command line.

The first argument is read by the shell into the parameter $1, The second
argument into $2, and so on. After $9, the arguments must be enclosed in
brackets, for example, ${10}, ${11}, ${12}.Some shells doesn't support this
method. In that case, to refer to parameters with numbers greater than 9, use
the shift command; this shifts the parameter list to the left. $1 is lost,while
$2 becomes $1, $3 becomes $2, and so on. The inaccessible tenth parameter
becomes $9 and can then be referred to.

Example:

#!/bin/bash
# Call this script with at least 3 parameters, for example
# sh scriptname 1 2 3

echo "first parameter is $1"

echo "Second parameter is $2"

echo "Third parameter is $3"

exit 0

Output:
[root@localhost ~]# sh parameters.sh 47 9 34

first parameter is 47

Second parameter is 9

Third parameter is 34

[root@localhost ~]# sh parameters.sh 4 8 3

first parameter is 4

Second parameter is 8

Third parameter is 3


In addition to these positional parameters, there are a few other special
parameters used by shell.Their significance is noted bellow.

$* - It stores the complete set of positional parameters as a single string.
$@ - Same as $*, But there is subtle difference when enclosed in double quotes.
$# - It is set to the number of arguments specified.This lets you design scripts
that check whether the right number of arguments have been entered.
$0 - Refers to the name of the script itself.

Setting Values of Positional Parameters

You can't technically call positional parameters as shell variables because all
variable names start with a letter. For instance you can't assign values to $1,
$2.. etc. $1=100 or $2=venu is simply not done. There is one more way to assign
values to the positional parameters, using the set command.

$ set Helping hands are holier than praying lips

The above command sets the value $1 with “Helping” , $2 with “hands” and so on.
To verify, use echo statement to display their values.

$ echo $1 $2 $3 $4 $5 $6 $7

Helping hands are holier than praying lips

You can simply use $* or $@

$ echo $*

Helping hands are holier than praying lips

$ echo $@

Helping hands are holier than praying lips

Using Shift on Positional Parameters

We have used set command to set upto 9 words. But we can use it for more.

$ set A friend who helps when one is in trouble is a real friend

$ echo $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11

A friend who helps when one is in trouble A0 A1


Observe that last two words in the output. These occurred in the output because
at a time we can access only 9 positional parameters. When we tried to refer to
$10 it was interpreted by the shell as if you wanted to out put the value of $1
and a 0. Hence we got A0 in the output.
Does that mean the words following the ninth word have been lost? No. If not,
then where have they gone?. They are very much there, safe with the shell But to
reach them we must do the following.

$shift 4

$ echo $1 $2 $3 $4 $5 $6 $7 $8 $9

when one is in trouble is a real friend


Now where have the first seven words gone? They have been shifted out.The first
four words lost for ever, as we did not take the precaution to store them else-
where. What should we have done is:

$ set A friend who helps when one is in trouble is a real friend

$ a=$1

$ b=$2

$ c=$3

$ d=$4

$ shift 4

$ echo $a $b $c $d $1 $2 $3 $4 $5 $6 $7 $8 $9

A friend who helps when one is in trouble is a real friend


Note:In the Korn and bash shells you can refer directly to arguments where
n is greater than 9 using braces. For example, to refer to the 57th positional
parameter, use the notation ${57}.some shells may not support this method.


$ set A friend who helps when one is in trouble is a real friend

$ echo ${12}

real

$ echo ${13}

friend


Bracket notation for positional parameters leads to a fairly simple way of
referencing the last argument passed to a script on the command line.

$ echo ${!#}

friend


$* and $@

Let us look at the subtle difference between $* and $@.

First create three files fileA, fileB, “file temp”
cat > fileA
I LOVE INDIA
Ctrl+d

cat > fileB
HELLO WORLD
Ctrl+d

cat > temp\ file
This file name contains blank space
Ctrl+d

Example:

#!/bin/bash
# Usage: sh arguments.sh fileA fileB temp\ file

echo -e "\033[1mDisplay files content using \$* \033[0m"

cat $*

echo -e "\033[1mDisplay files content using \$@ \033[0m"

cat $@

exit 0

Run the script with file names as arguments.

Output:
[root@localhost ~]# sh arguments.sh fileA fileB temp\ file
Display files content using $*
I LOVE INDIA
HELLO WORLD
cat: temp: No such file or directory
cat: file: No such file or directory
Display files content using $@
I LOVE INDIA
HELLO WORLD
cat: temp: No such file or directory
cat: file: No such file or directory

So there is no difference between cat $* and cat $@.

Modify arguments.sh script as


#!/bin/bash
# Usage: sh arguments.sh fileA fileB temp\ file

echo -e "\033[1mDisplay files content using \"\$*\" \033[0m"

cat "$*"

echo -e "\033[1mDisplay files content using \"\$@\" \033[0m"

cat "$@"

exit 0

Now again run the script with file names as arguments.

Output:
[root@localhost ~]# sh arguments.sh fileA fileB temp\ file
Display files content using "$*"
cat: fileA fileB temp file: No such file or directory
Display files content using "$@"
I LOVE INDIA
HELLO WORLD
This file name contain blank space

Now there is a difference, the two cat commands would become:

cat “fileA fileB temp file”
cat fileA fileB 'temp file'

On execution, the first of these commands would give an error since there does
not exist a file with the name “fileA fileB temp file”. As against this, the
second cat command would display the contents of the files fileA, fileB and
“temp file”. So what you observed ,when not enclosed within "double quotes"
$* and $@ behaves exactly similarly, and when enclosed in "double quotes" there
is a subtle difference.

Thursday, November 12, 2009

Posted by venu k
5 comments | 1:17 AM

Method 1:


#!/bin/bash
#
# SCRIPT : leapyear.sh
# PURPOSE: Checks whether given year is a leap year or not
# USAGE : sh leapyear.sh
# If Year value not supplied, it takes current year as default
#
# This script based on, One year has the length of 365 days, 5 hours,
# 48 minutes and 47 seconds. Because this is rather non-functional,
# a normal year has been given 365 days and a leap year 366 days.

#####################################################
############### DEFINE FUNCTIONS HERE ####################
#####################################################

Leap()
{

# This function tells you if the argument is a leap year or not...

YEAR=$1
NO_OF_DAYS=$(cal $YEAR |egrep "^[ 0-9][0-9]| [ 0-9][0-9]$" |wc -w)


# A single parameter to cal specifies the year (1 - 9999) to be displayed;
# note the year must be fully specified: “cal 89” will not display a calendar
# for 1989.

# Use egrep or grep -E both are same

# cal command pipes total months and dates to egrep, egrep remove all lines
# not starting with number or ending with number, then pipes remaining lines
# to wc command. wc command counts total number of words(days).

if [[ $NO_OF_DAYS -eq 365 ]]
then
echo "$YEAR Is Not A Leap Year "
else
echo "$YEAR Is A Leap Year"
fi

}

#####################################################
############### MAIN PROGRAM STARTS HERE #################
#####################################################

Year=${1:-$(date +%Y)}
if [ $Year -lt 1 -o $Year -gt 9999 ]
then
echo "Illegal Year Value: Use 1-9999"
exit 1
fi

Leap $Year

Method 2:


#!/bin/bash
#
# SCRIPT : leapyear.sh
# PURPOSE: Checks whether given year is a leap year or not
# USAGE : sh leapyear.sh
# If Year value not supplied, it takes current year as default
#
# This script based on,A leap year comes every 4 years,
# but not every 100 years, then again every 400 years.


#####################################################
############### ARGUMENTS CHECKING #####################
#####################################################

YEAR=${1:-`date +%Y`}

if [ $YEAR -lt 1 -o $YEAR -gt 9999 ]
then
echo "Illegal Year Value: Use 1-9999"
exit 1
fi

#####################################################
############### DECLARE VARIABLES HERE ###################
#####################################################

rem1=$((YEAR%4))
rem2=$((YEAR%100))
rem3=$((YEAR%400))

#####################################################
############## MAIN PROGRAM STARTS HERE ##################
#####################################################

if [ ${rem3} = "0" ]
then
echo "$YEAR Is A Leap Year"
exit
fi

if [ ${rem2} = "0" -a ${rem3} != "0" ]
then
echo "$YEAR Is Not A Leap Year"
exit
fi

if [ ${rem1} = "0" -a ${rem2} != "0" ]
then
echo "$YEAR Is A Leap Year"
else
echo "$YEAR Is Not A Leap Year"
fi

OUTPUT:

[root@localhost shell]# ./leapyear.sh
2009 Is Not A Leap Year
[root@localhost shell]# ./leapyear.sh 2100
2100 Is Not A Leap Year
[root@localhost shell]# ./leapyear.sh 2104
2104 Is A Leap Year
[root@localhost shell]# ./leapyear.sh 21000
Illegal Year Value: Use 1-9999
[root@localhost shell]# ./leapyear.sh 1996
1996 Is A Leap Year

Monday, November 2, 2009

Posted by venu k
2 comments | 4:21 AM
This script not replaces cp command. This is a sample script for practice purpose.
I am going to develop more elegant script, which fulfil most of the cp command strengths.
I will post complete version of the script as soon as possible,
I shall really appreciate all comments and suggestions to improve this script.

#!/bin/bash
#
# SCRIPT: ddcopy_progress.sh
# PURPOSE: This script is used to watch progress of copying.
#
# Note: I am using destination file as $$.temp .This is because,
# after testing you can easily delete temp files using
# rm -f *.temp

#############################################
# Arguments Checking #
#############################################

if [ $# -ne 1 ] # Look for exactly one parameter
then
echo "..............Usage Error........."
echo "Usage: $0 Sourcefil"
exit 1
fi

if [ ! -e $1 ] # Check source file exist or not
then
echo "File $1 not exist"
exit 1
fi

#############################################
# DEFINE VARIABLES HERE #
#############################################

Seek=0 # Skip BLOCKS bs-sized blocks at start of output
Skip=0 # Skip BLOCKS bs-sized blocks at start of input
Bsize=128000 # Block size
size=`stat -c %s $1`
blocks=$((size/Bsize)) # Total blocks of input file

lastblock=$((size%Bsize)) # Last block, which size < $Bsize

# If last block size is > 0 then add 1 block to existing blocks.

if [ $lastblock -gt 0 ]
then
let blocks++
fi

# I am dividing screen width 60 as 20 parts.Each part is filled with color
# after each iteration.

# Make blocks count dividable by 20.

addblocks=$((blocks%20))
if [ $addblocks -gt 0 ]
then
adjustblocks=$((20-addblocks))
blocks=$((blocks+adjustblocks))
fi

Count=$((blocks/20))

# Count variable contain number of blocks to be copied for each iteration

###############################################
# MAIN PROGRAM STARTS HERE #
###############################################

printf "\e[40m\e[43m%60s\n\e[A" " "

for ((i=1;i<=20;i++))
do

dd if=$1 of=$$.temp bs=128kB seek=$Seek skip=$Skip count=$Count 2>/dev/null
Skip=$((Skip+$Count))
Seek=$((Seek+$Count))
j=$((j+3)) # 60/20 each part is 3 chars length
printf "\e[40m\e[7m%${j}s\n\e[A" " "
# echo -e "\033[7m \c"
# sleep 1 # Uncomment it for small files

done
printf "\e[0m\n"
#echo -e "\033[0m"

Output:
Screen Shot1:

Screen Shot2:

Screen Shot3:

Screen Shot4:

Observation:
I tested above script with different block count.But I didn't get accurate result.
Some times less count script given good result, some times more block count given
good result.
I copied 1.8 GB Movie file with this script.With time command it has give bellow
result.

real 1m12.646s
user 0m0.043s
sys 0m7.854s

From my observation this script has taken less time compared with mouse copy and
paste method. Copy and paste has taken 1m14.02s averagely.

Sunday, November 1, 2009

Posted by venu k
7 comments | 11:56 AM

#!/bin/bash
#
# SCRIPT: bigfile.sh
# PURPOSE: This script is used to create a text file that
# has a specified number of lines that is specified
# on the command line.
#


usage()
{

echo "............USAGE ERROR............"
echo "USAGE: $0 <number_of_lines_to_create>"
}

# Argument Checking

if [ $# -ne 1 ] # Looking for exactly one parameter
then
usage # Usage error was made
exit 1 # Exit on a usage error
fi

# Define files and variables here

LINE_LENGTH=80 # Number of characters per line
OUT_FILE=bigfile.$$ # New file to create
>$OUT_FILE # Initialize to a zero-sized file
TOTAL_LINES=$1 # Total number of lines to create
LINE_COUNT=0 # Character counter
CHAR=X # Character to write to the file

# Beginning of Main

while ((LINE_COUNT < TOTAL_LINES))
do
CHAR_COUNT=0 # Initialize the CHAR_COUNT to zero on every new line

while ((CHAR_COUNT < LINE_LENGTH)) # Each line is fixed length
do
echo -e "$CHAR\c" >> $OUT_FILE # Echo a single character
let CHAR_COUNT++ # Increment the character counter
done

let LINE_COUNT++
echo>>$OUT_FILE # Give a newline character
done