cs2044_Lecture5

cs2044_Lecture5 - CS2044 - Advanced Unix Tools Spring 2010...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS2044 - Advanced Unix Tools Spring 2010 Lecture 5 David Slater dms236 at cornell.edu March 3, 2010 David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools Organization Homework is due on Friday at 6 pm. Questions about homework????????...? David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools Some Review What does this print? echo $ { PWD##*/ } David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools Some Review What does this print? echo $ { PWD##*/ } The name of the current directory (not the path) What if we do: x=2 y=’x’ echo $ { !y } David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools Some Review What does this print? echo $ { PWD##*/ } The name of the current directory (not the path) What if we do: x=2 y=’x’ echo $ { !y } This wil print 2. David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools More Review Here is a script: #! /bin/bash # scriptname: something.sh for i in $(seq 1 $#) do echo $ { !i } done If I run it with ./something.sh abc def ghi klm what does it print? David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools More Review Here is a script: #! /bin/bash # scriptname: something.sh for i in $(seq 1 $#) do echo $ { !i } done If I run it with ./something.sh abc def ghi klm what does it print? It will print abc def ghi klm each on its own line. As written this is equivalent to for i in $ , but this way would allow us to loop over only some of the input parameters. David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools Random Bash Thing Of The Day xargs xargs constructs an argument list for an arbitrary unix command using stdin and executes the command For example find . -name "*.tmp" | rm rm: missing operand Try ‘rm -- help’ for more information. but find . -name "*.tmp" | xargs -t rm " rm ./temp.tmp-t flag has it print each command as it is executed. David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools More Or more realistically find . -name "*.tex" | xargs grep string and ls | xargs-t-I {} mv {} {}.old The second of which renames all files in the current directory with the .old suffex xargs is very useful. remember it takes stdout and converts it to a list of strings seperated by a space. David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools Do you grok gawk?...
View Full Document

This document was uploaded on 03/15/2010.

Page1 / 31

cs2044_Lecture5 - CS2044 - Advanced Unix Tools Spring 2010...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online