Presentation is loading. Please wait.

Presentation is loading. Please wait.

 Prepared by: Eng. Maryam Adel Abdel-Hady

Similar presentations


Presentation on theme: " Prepared by: Eng. Maryam Adel Abdel-Hady"— Presentation transcript:

1  Prepared by: Eng. Maryam Adel Abdel-Hady eng.maryamadel@yahoo.com

2  Use to perform arithmetic operations.  Syntax: o expr op1 math-operator op2  Examples: $ expr 1 + 3 $ expr 2 - 1 $ expr 10 / 2 $ expr 20 % 3 $ expr 10 \* 3 $ echo `expr 6 + 3`  Note: o expr 10 \* 3 - Multiplication use \* and not * since its wild card. o If you define a variable x that equal expr 2 +3 >> NO SPACE between equal and expr >> x=`expr 2+3`

3 $ echo `expr 6 + 3`  Note: (1) First, before expr keyword we used ` (back quote) sign not the (single quote i.e. ') sign. Back quote is generally found on the key under tilde (~) on PC keyboard OR to the above of TAB key. (2) Second, expr is also end with ` i.e. back quote. (3) Here expr 6 + 3 is evaluated to 9, then echo command prints 9 as sum (4) Here if you use double quote or single quote, it will NOT work ----------------------------- $ echo "expr 6 + 3" # It will print expr 6 + 3 $ echo 'expr 6 + 3' # It will print expr 6 + 3

4  Example: $ echo "Today is date" Can't print message with today's date. $ echo "Today is `date`". It will print today's date as, Today is Tue Jan....,Can you see that the `date` statement uses back quote?

5 Use to get input (data from user) from keyboard and store (data) to variable.  Syntax: read variable1, variable2,...variableN ----------------- Ex: echo "Your first name please:" read fname echo "Hello $fname, Lets be friend!"

6  To run two command with one command line.  Syntax: o command1;command2  Examples: o $ date;who Will print today's date followed by users who are currently login. Note that You can't use o $ date who for same purpose, you must put semicolon in between date and who command.

7 IF Command

8 #!/bin/bash number=1 if test $number -eq 1 then echo "Number equals 1" else echo "Number does not equal 1“ fi

9  #Script to print file o #!/bin/bash o echo “ please enter number” o read n o if cat $n o then o echo “file $n found " o fi -------------  # Script to test rm command and exist status o #!/bin/bash o echo “ please enter number” o read n o if rm $n o then o echo "$n file deleted" o fi

10  # Script to see whether argument is positive o #!/bin/bash o echo “ please enter number” o read n o if test $n -gt 0 o then o echo "$n number is positive" o fi

11

12  # Script to see whether argument is positive or negative o #!/bin/bash o echo “ please enter number” o read n o if test $n -gt 0 o then o echo "$n number is positive" o else o echo "$n number is negative" o fi

13  # Script to choose from list and print a statement according to you choice o ch=0 o echo "1. Unix (Sun Os)" o echo "2. Linux (Red Hat)" o echo -n "Select your os choice [1 or 2]? " o read ch o if test $ch -eq 1 o then o echo "You Pick up Unix (Sun Os)" o else if test $ch -eq 2 o then o echo "You Pick up Linux (Red Hat)“ o else o echo "What you don't like Unix/Linux OS." o fi

14 Loops in Shell Scripts

15 for (( expr1; expr2; expr3 )) do..... repeat all statements between do and done until expr2 is TRUE …… done --------------- Ex: for (( i = 0 ; i <= 5; i++ )) do echo "Welcome $i times" done

16 while [ condition ] do command1 command2 command3...... done ---------------- Ex: i=1 while [ $i -le 10 ] do echo “Welcome $i” i=`expr $i + 1` done

17 Functions

18  Function is series of instruction/commands. Function performs particular activity in shell.  Why to write function? o l Saves lot of time. o l Avoids rewriting of same code again and again o l Program is easier to write. o l Program maintains is very easy -------------------------- function-name ( ) { command1 command2........ commandN return }

19 Programming Languages in UBUNTU

20 (1) C/C++ Programs

21  http://www.wikihow.com/Compile-a-C/C%2B%2B-Program-in- Ubuntu http://www.wikihow.com/Compile-a-C/C%2B%2B-Program-in- Ubuntu  Steps: 1. Open up a terminal on Ubuntu Linux and install the build-essential package by typing the following command in the terminal Type/Copy/Paste: sudo apt-get install build-essential This will install the necessary C/C++ development libraries for your Ubuntu Linux system to create C/C++ programs. 2. Create a directory and a sub directory to hold your C/C++ programs and your main HelloWorld program. Type/Copy/Paste: mkdir -p CCPP/HelloWorld We are using CCPP for the main directory to hold our created C/C++ programs which stands for C and C++ programs directory and we are using the sub directory HelloWorld to hold our main program.

22 3. Then we will change into our created directory by issuing the following command Type/Copy/Paste: cd CCPP/HelloWorld 4. Next we will use a text editor such as gedit or nano to create our C or C++ source code using the following command.

23 Example for: C Program

24 5. For example for a C source code file we would issue the following command Type/Copy/Paste: gedit main.c or Type/Copy/Paste: nano main.c o This command for creating a script file called main.c 6. Enter the following C source code below: o Type/Copy/Paste: #include int main() { printf("\nHello World,\nWelcome to my first C program in Ubuntu Linux\n\n"); return(0); } 7. Save the file as main.c and exit

25 8. To compile the C program: o Type/Copy/Paste: gcc -Wall -W -Werror main.c -o HelloWorldC o The first line will invoke the GNU C compiler to compile the file main.c and output (-o) it to an executable called HelloWorldC. o The options -Wall -W and -Werror instruct the compiler to check for warnings. 9. If you should happen to get permission errors, you need to make the file executable. You can do this by issuing the following commands below o Type/Copy/Paste: chmod +x HelloWorldC

26 10. In order to execute your program you will have to type in the following commands.To execute the C program version of the program: Type/Copy/Paste:./HelloWorldC

27 Example for: C++ Program

28 5. For example for a C++ source code file we issue the following command o Type/Copy/Paste: gedit main.cpp o or o Type/Copy/Paste: nano main.cpp o This command for creating a script file called main.c 6. Add the following lines below to create your C++ source code: Type/Copy/Paste: #include using namespace std; int main() { cout<<"\nHello World,\nWelcome to my first C ++ program on Ubuntu Linux\n\n"<<endl; return(0); } 7. Save the file as main.cpp and exit

29 8. To compile the C program: o If you are compiling the C++ program version of Hello World type in the terminal Type/Copy/Paste: g++ -Wall -W -Werror main.cpp -o HelloWorldCPP 9. If you should happen to get permission errors, you need to make the file executable. You can do this by issuing the following commands below o Type/Copy/Paste: chmod +x HelloWorldCPP

30 10. In order to execute your program you will have to type in the following commands. To execute the the C++ program version of the program: o Type/Copy/Paste:./HelloWorldCPP

31 (2)Java

32  First you must have Java application such oracle Java,to install it follow this steps: How to Install Oracle Java on Ubuntu Linux  or you can write this command to install a Java application sudo apt-get install openjdk-6-jdk Java –version  to show the version Gedit userinput.java  write your java program o Show this video: http://youtu.be/3w9HckeYY-Q  Then you can follow these steps http://www.wikihow.com/Create-Your-First-Java-Program-on-Ubuntu-Linux

33 (3)C#

34  http://developer.ubuntu.com/resources/programming- languages/c-sharp/ http://developer.ubuntu.com/resources/programming- languages/c-sharp/

35  Mono is a software platform designed to allow developers to easily create cross-platform applications. It is an open source implementation of Microsoft’s.Net Framework based on the ECMA standards for C# and the Common Language Runtime. We feel that by embracing a successful, standardized software platform, we can lower the barriers to producing great applications for Linux.  هذا البرنامج يعمل لاكثر من لغة http://developer.ubuntu.com/resources/programming-languages/c- sharp/ http://linuxpoison.blogspot.com/2010/11/how-to-compile-and-run- c-net.html

36 (4)PHP

37 http://www.allaboutlinux.eu/how-to-run-php-on-ubuntu/


Download ppt " Prepared by: Eng. Maryam Adel Abdel-Hady"

Similar presentations


Ads by Google