Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Development and Darwin (http://www.mac-forums.com/forums/os-x-development-darwin/)
-   -   Now that is cool! (http://www.mac-forums.com/forums/os-x-development-darwin/278279-now-cool.html)

V6Pony 06-30-2012 11:16 AM

Now that is cool!
 
#!/bin/bash
echo "Enter lower case text here"
read foo
var=`echo $foo | tr "{a-z}" "{A-Z}"`
# {a-z} Matches a through z
# {A-Z} matches A through Z
echo $var

but I'm not sure I fully understand ` ` I think it allows the output from an application to be stored in a variable. In this example the output from echo $foo | tr "{a-z}" "{A-Z}" is saved in var. So what does tr do? Change lower case to upper case. Why does it do that?

The tr utility copies the given input to produced the output with substitution or deletion of selected characters. tr abbreviated as translate or transliterate. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set i.e. it is used to translate characters.

vansmith 06-30-2012 11:23 AM

It's called command substitution (see 3.4.5 here for more info).

Looks like you're progressing well!

Slydude 06-30-2012 11:36 AM

/Slydide trembles in fear as he bookmarks bash guide for future use. :\

vansmith 06-30-2012 11:57 AM

That would be wise. Someday the blog will be powered by bash scripts... :P

Dysfunction 06-30-2012 03:02 PM

Quote:

Originally Posted by vansmith (Post 1419841)
That would be wise. Someday the blog will be powered by bash scripts... :P

sed 's/bash/ksh/g'

:P


All times are GMT -4. The time now is 01:57 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.