Showing posts with label variables. Show all posts
Showing posts with label variables. Show all posts

Friday, September 27, 2013

PHP Part-2

Hi friends, this is my second blog on PHP and today we will learn about:
  • How to create and store variables?
  • What echo do?
  •  How to give comment?
  • What is heredoc?
Variable: By using variables we can store strings, a word or a number. In PHP, data types are assigned automatically. There is no need to assign data types manually.   
Variable form:
          $variable_name=value;
This variable name is case sensitive. There are some standard ways to write variable name:
1.     Name of the variable must start with alphabetic word or “_”.
2.     Variable name must consist only of alpha-numeric words and underscores.
3.     If there is more than one word in variable then it must be separated by “_” or by capitalization.

    Echo: Echo is used to output the string. Echo uses quotes (“ “) to define beginning and end of the string. At the time of echoing variable there is no need for quotations.

    Comment: Comments are used to document the project or code.
For single line comments (//) are used and for multiline comments (/*……….*/).

 String: There are two types of strings:
1.     Stored string: $my_string= ”Hey Jak”;
echo $my_string;
2.     Direct string: echo “ Hi Jak “;
Strings are quoted in two ways, double quotes (“ ”) and single quotes(‘ ‘).
 sHeredoc: This is the unique feature of PHP, it lets programmer create multi-line strings without using quotes. It begin with (<<<) and some identifier and it ends with identifier followed by semi-colon (;).

 Example: example demonstrating use of variable, comment, echo and heredoc.




















Saturday, February 9, 2013

Basic of Shell Programming

Why shell?
Even though there are various graphical interfaces available for Linux, the shell still is a very neat tool. The shell is not just a collection of commands but really good programming language. You can automate a lot of tasks with it. The shell is very good for system administrator tasks. You can quickly try out if your idea which makes it very useful for simple prototyping and it is very useful for small utilities that perform some relatively simple tasks where efficiency is less important than ease of configuration, maintenance and portability.
Let's see how it works:
Creating a script file:-
There are two ways to create a script file, i.e. we can save script file with .sh extension that will indicate that it's a shell file or we can write “#!/bin/sh” at the very first line. The “#!” character tells the system that the first argument that follows on the line is the program to be used to execute this file. In this case “/bin/sh” is shell we use. And for creating script file we can used any text editor like GEDIT, VI editor etc.
Variables:-
As we know every programming language needs variables, without variables it’s next to impossible to do programs. But in shell programming we don't have data types. All variables are of string data types and we don't need to declare it, to assign values to variables. Syntax is as follows:-
Variable_name=value
Even we don't need terminator operator to end statement, actually its optional, you can used it if you want.
Examples:-
str=”This is shell Programming ”
num=169
You can also print the values of variables by just using “$” symbol in front of variables.
echo “values of num is=$num”
It will print value of num that is 169 on the screen.
Comments:-
In Shell programming we can use comments for user understanding using # symbol at first of your statements.
Example:-
#This is my first shell program.
#Program based on Linux.
Reading values from Keyboard:-
This is very important to take values from user, as I mention above shell programming doesn't have data type so we don't need to specify which type of values we need to read. To read values from keyboard just use “read” command as given below:-
echo "Enter value for A"
read A
echo "Enter value for B"
read B
C=`expr $A + $B` - Line5
echo "Addtion is =$C"
Now, here some more things come at Line5 that is back quotes and expression (expr). To do any kind of calculation we have to follow this procedure.
In shell programming we have many things to do, but above things are the basic which we have to know at the initial stage of shell programming. For more information you can search it on www.google.com or you can also mail me on panditdilipr@gmail.com .