{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs2044_Lecture4

cs2044_Lecture4 - CS2044 Advanced Unix Tools Spring 2009...

Info icon This preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
CS2044 - Advanced Unix Tools Spring 2009 Lecture 4 David Slater dms236 at cornell.edu March 1, 2010 David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Image of page 1

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

View Full Document Right Arrow Icon
Organization Homework 1 Due on Friday Any Questions About The Homework? Note: Print Lower Boundary Of Each Bin Not Upper Boundaryt David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Image of page 2
Some Review If Syntax if [ condition ]; then cmds; fi for Syntax for i in some group; do cmds; done "$*" expands to ”$1 $2 ... $n” "[email protected]" expands to ”$1” ”$2” ... ”$n” Almost always want [email protected] David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Image of page 3

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

View Full Document Right Arrow Icon
Random Bash Tip Of The Day The environment variable $PS1 stores your default prompt. You can modify this variable to spruce up your prompt if you like: Example First echo $PS1 to see its current value \s-\v\$ (default) It consists mostly of backslash-escaped special characters, like \s (name of shell) and \v (version of bash). There are a whole bunch of options, which can be found at http://www.gnu.org/software/bash/manual/bashref.html#Printing-a-Prompt David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Image of page 4
Modifying Your Prompt Once you have a prompt you like, set your $PS1 variable Define your prompt [email protected]: $ export PS1="New Prompt String" Type this line at the command prompt to temporarily change your prompt (good for testing) Add this line to ~/.bashrc or ~/.bash_profiles to make the change permanent. Note: Parantheses must be used to invoke the characters. Examples PS1="\u \w \t_" slater ~ 12:12:12_ PS1="\W \j \d\:" ~ 0 Oct 02: David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Image of page 5

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

View Full Document Right Arrow Icon
Dealing with improper input Last time we looked at a script lcount.sh: #! /bin/bash # lcountgood.sh i="0" for f in "[email protected]" do j=‘wc -l < $f‘ i=$(($i+$j)) done echo $i Which works great, unless we pass it bad input. Say we pass it Asf* , and there is no file that matches that. It returns the error message ./lcount.sh: line 5: Asf*: No such file or directory. David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Image of page 6
Improper input The easiest way to fix this is to simply check if the file exists each time through the loop. #! /bin/bash # lcountgood.sh i="0" for f in "[email protected]" do if [ -f $f ] then j=‘wc -l < $f‘ i=$(($i+$j)) fi done echo $i David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Image of page 7

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

View Full Document Right Arrow Icon
thumbnails Lets look at another script: #!/bin/bash # This script will create a thumbs/ directory containing thumbnails # of all JPEG files in the current folder. if [ ! -e thumbs ] ; then mkdir thumbs if [[ $? -ne 0 ]] ; then echo HELP exit fi fi for i in *.jpg *.jpeg *.JPG *.JPEG do if [[ ! -f "$i" ]] then continue fi echo "Resizing $i" jpegtopnm < "$i" | pnmscale -xsize=200 | pnmtojpeg > thumbs/"$i" 2> /dev/null done David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Image of page 8
How the shell works It is time we talked a bit about how the shell works. Processes in UNIX are organized in a tree. Every process has a parent process that started it or is responsible for it Every process has its own context memory: The environment.
Image of page 9

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

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern