16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Unix</strong> Shells<br />

two lines<br />

!Y@Y@Z@Z@ZY<br />

cat > file3 &2<br />

exit 1 ;;<br />

esac<br />

while :<br />

do<br />

ans=<br />

# portable way to keep cursor on same line<br />

# tr -d '\012' >&2<br />

echo "$prompt" | tr -d '\012' >&2<br />

read ans<br />

[ -z "$ans" ] && ans="$2" # get default from command<br />

case "$ans" in<br />

[Yy]|YES|yes) exit 0 ;;<br />

[Nn]|NO|no) exit 1 ;;<br />

*) echo "Please answer y/n" >&2 ;;<br />

esac<br />

done<br />

! MVSED<br />

#!/bin/sh<br />

# @(#)mvsed - rename files using sed-script<br />

# rename a list of files using a sed(1) command<br />

# mvsed [-e] sed-script file ...<br />

# -e just outputs <strong>the</strong> "mv" commands<br />

# (no files are renamed)<br />

# e.g.<br />

# mvsed -e 's/w/BIGW/' awk passwd wall<br />

# outputs:<br />

# mv awk aBIGWk<br />

# mv passwd passBIGWd<br />

# mv wall BIGWall<br />

if [ $# = 0 ]<br />

<strong>the</strong>n<br />

echo "`basename $0`: [-e] sed-script file ..." >&2<br />

exit 2<br />

fi<br />

ECHO=<br />

case "$1" in<br />

-e) ECHO=echo; shift;;<br />

esac<br />

sed="$1"; shift<br />

for file<br />

do<br />

22

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!