Presentation is loading. Please wait.

Presentation is loading. Please wait.

© Prepared By: Razif Razali 1 TMK 265: UNIX SYSTEM CHAPTER FOUR – QUOTING IN DETAIL.

Similar presentations


Presentation on theme: "© Prepared By: Razif Razali 1 TMK 265: UNIX SYSTEM CHAPTER FOUR – QUOTING IN DETAIL."— Presentation transcript:

1 © Prepared By: Razif Razali 1 TMK 265: UNIX SYSTEM CHAPTER FOUR – QUOTING IN DETAIL

2 © Prepared By: Razif Razali 2 OVERVIEW –Grouping / gathering Unix command –First program – “Piping” and “redirection”

3 GROUPING UNIX COMMANDS Normally you type one command at a time, following each command by an ENTER.Normally you type one command at a time, following each command by an ENTER. However, it is possible to put multiple commands on the same line.However, it is possible to put multiple commands on the same line. Example:Example: –$ who; ls; cal –$ (cal 2006; cal 2007; cal 2008) > summer In this case, calendar for 2006, 2007 and 2008 will be redirected into the summer file. © Prepared By: Razif Razali 3

4 PIPES ( | ) A pipe is a way to connect the output of one program to the input of another program without any temporary file.A pipe is a way to connect the output of one program to the input of another program without any temporary file. A pipe is nothing but a temporary storage place where the output of one command is stored and then passed as the input for second commandA pipe is nothing but a temporary storage place where the output of one command is stored and then passed as the input for second command © Prepared By: Razif Razali 4 Output of 1 st command Take input from 1 st command for this command |

5 PIPES Suppose you want to display the calendar for the 2006, 2007 and 2008, one right after the other.Suppose you want to display the calendar for the 2006, 2007 and 2008, one right after the other. $ (cal 2006; cal 2007; cal 2008) But when we see the output, you could only see the 2008 calendar.But when we see the output, you could only see the 2008 calendar. Solution – Using pipe in UNIX.Solution – Using pipe in UNIX. Example:Example: –$ (cal 2006; cal 2007; cal 2008) | more Or –$ (cal 2006; cal 2007; cal 2008) | pg © Prepared By: Razif Razali 5

6 REDIRECTION The shell allow the user to redirect the standard output so that the output goes into an ordinary file instead.The shell allow the user to redirect the standard output so that the output goes into an ordinary file instead. Example:Example: –$ cal 2007 > Calendar.file > is a redirection operator. –$ cal 2008 >> Calendar.file Add output to a file using append operator (>>) –$ mail jones < my.message Send the contents of the file my.message to the user jones. –$ wc output Invokes the wc utility to count the lines, words, and characters in the file input, the redirect the result into the file output. © Prepared By: Razif Razali 6

7 Example of Redirection © Prepared By: Razif Razali 7 $ cat File1 This is File1 $ cat File2 This is File2 $ cat File1 >> File2 $ cat File2 This is File2 This is File1 $ cat File1 File2 > File3 $ cat File3 This is File2 This is File1 $

8 Creating a file by direction User also can create a new file by using the redirectionUser also can create a new file by using the redirection Example:Example: © Prepared By: Razif Razali 8 $ ls File1File2 $ ls > File3 $ls File1File2File3

9 WRITING A FIRST SCRIPT SCRIPT To successfully write a shell script, you have to do three things:To successfully write a shell script, you have to do three things: –Write a script –Give the shell permission to execute it –Put it somewhere the shell can find it © Prepared By: Razif Razali 9

10 echo Command Use echo command to display text or value of variable.Use echo command to display text or value of variable. echo [options] [string, variables...] Displays text or variables value on screen. Options -n Do not output the trailing new line. -e Enable interpretation of the following backslash escaped characters in the strings: \a alert (bell) \b backspace \c suppress trailing new line \n new line \r carriage return \t horizontal tab \\ backslashecho [options] [string, variables...] Displays text or variables value on screen. Options -n Do not output the trailing new line. -e Enable interpretation of the following backslash escaped characters in the strings: \a alert (bell) \b backspace \c suppress trailing new line \n new line \r carriage return \t horizontal tab \\ backslash For e.g. $ echo -e "An apple a day keeps away \a\t\tdoctor\n"For e.g. $ echo -e "An apple a day keeps away \a\t\tdoctor\n" © Prepared By: Razif Razali 10

11 More about Quotes There are three types of quotesThere are three types of quotes © Prepared By: Razif Razali 11 QuotesNameMeaning " Double Quotes "Double Quotes" - Anything enclose in double quotes removed meaning of that characters (except \ and $). ' Single quotes 'Single quotes' - Enclosed in single quotes remains unchanged. ` Back quote`Back quote` - To execute command 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

12 Exercise Write a script to display the following output in my_scripttwo file.Write a script to display the following output in my_scripttwo file. © Prepared By: Razif Razali 12


Download ppt "© Prepared By: Razif Razali 1 TMK 265: UNIX SYSTEM CHAPTER FOUR – QUOTING IN DETAIL."

Similar presentations


Ads by Google