Thursday, December 27, 2012

Linux Boot Loader                                                           Features of Bash Shell

It is very easy to learn bash shell scripting. There are different Unix shells like bash, ksh, zsh, sh etc. Please make sure that which shell do you want to use while running the script, because syntax of each shell might be different. Before going to develop shell script, your logic or flow of the script should be clear then only you can develop shell script very easily. It is very important to have clear understanding of when or where not to use shell script

 

For Fibonacci series shell script, need to know the exact number series. It will be as :

1              1              2              3              5              8              13           21            34          etc.

Please see below is the script to get desired output. 

######################Fibonacci.sh###############################

echo "How many numbers do you want of Fibonacci series ?"

  read total

  x=0

  y=1

  i=2

  echo "Fibonacci Series up to $total terms :: "

  echo "$x"

  echo "$y"

  while [ $i -lt $total ]

  do

      i=`expr $i + 1 `

      z=`expr $x + $y `

      echo "$z"

      x=$y

      y=$z

  done

Click to  know more about: Difference of Linux and Unix

#####################################################################

Now just save it as Fibonacci.sh and give the input as how many numbers you want of . Your output will be as follows: 

#####################################################################

root@hello:~/ctier/test/JBoss#

root@hello:~/ctier/test/JBoss# ./Fibnonacci.sh

How many numbers do you want of Fibonacci series ?

10

Fibonacci Series up to 10 terms ::

0

1

1

2

3

5

8

13

21

34

root@hello:~/ctier/test/JBoss#

#####################################################################

Before developing this script you should have clear understandings of while loop in shell script  and addition of numbers i.e. mathematical calculations in shell script.


mpstat command in Linux                                                        Ubuntu 12.10 features
Posted by Machindra Dharmadhikari On 12/27/2012 04:53:00 PM 1 comment

1 comment:

  1. Hello There,

    Zoooooooom! That’s how speedy and easy this read was! Looking forward to more of such powerful content on Difference of Linux and Unix!

    I read V7 Unix introduced the first version of the modern Standard I/O library studio as part of the system library. The next implementations increased the number of libraries significantly. Doesn't it adds overhead of loading unused libraries?

    But nice Article Mate! Great Information! Keep up the good work!

    Best Regards,
    Preethi

    ReplyDelete

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

    Chitika Ads 2

    Histat

    About

    Enter your email address:

    Delivered by FeedBurner