1 / 8

CSCI 330 The UNIX System

CSCI 330 The UNIX System. Shell Data Handling: Redirection and Piping. Output. The output statement of the shell is the “echo” command Syntax: echo [option] arg1 arg2 …argN its arguments can be strings or variables option “-n” will suppress trailing newline. Output with echo. Examples:

nedra
Download Presentation

CSCI 330 The UNIX System

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 330The UNIX System Shell Data Handling: Redirection and Piping

  2. CSCI 330 - The UNIX System Output • The output statement of the shell is the “echo” command Syntax: echo [option] arg1 arg2 …argN • its arguments can be strings or variables • option “-n” will suppress trailing newline

  3. CSCI 330 - The UNIX System Output with echo Examples: % echo “Hello Ray" Hello Ray % echo “Hello $USER" Hello a132436 % echo “It is now `date`” It is now Mon Feb 25 10:24:08 CST 2008

  4. CSCI 330 - The UNIX System Output Redirection (>) • Syntax: command > file Sends output of command to file, instead of to terminal • Examples: % du > status % (date; du) > status Calls the disk usage command for the current directory and redirects the output to a file called ‘status’ ( ) indicates command groups. Use it to combine the output of multiple commands. In this example, we place time and date in front of the disk usage

  5. CSCI 330 - The UNIX System Input Redirection (<) • Syntax: Command < file Command will read (take input) from file, instead of from terminal • Example: % tr “[A-Z]” “[a-z]” < report.input

  6. CSCI 330 - The UNIX System Examples: Output / Input • Redirecting input and output: % tr ‘[A-Z]’ ‘[a-z]’ < r.in > r.out • Output of command becomes input to next: % ls > temp.txt; wc < temp.txt • Eliminate the middleman: pipe % ls | wc

  7. CSCI 330 - The UNIX System Build the file ‘usage-status’ from the output of the ‘date’, ‘ls’, and ‘du’ commands Appending Output • Syntax: command >> file adds output of command at the end of file • If file does not exist, shell creates it • Examples: % date > usage-status % ls -l >> usage-status % du -s >> usage-status

  8. CSCI 330 - The UNIX System Summary: Redirections and Pipe

More Related