Shell Scripting
So I wrote my first shell script today. But I want it to be a little cooler. I want the variable $season to be converted to lowercase, so that if someone types in Fall, FALL, FaLl etc, it will still give them the fall message. I thought about using tr but I can't figure out a way to use tr with a variable
(tr [A-Z] [a-z] $season)=$season doesn't work. Any (simple) ideas?
Abhishek Reddy posted this at 05:48 — 21st November 2006.
He has: 3,348 posts
Joined: Jul 2001
Create another function that reads the season and converts it to lower case. Instead of calling [incode]read season[/incode] everywhere, call your new function instead.
Here's one way to convert a variable's contents to lowercase: [incode]foo=`echo $foo | tr A-Z a-z`[/incode].
Btw, is this homework?
teammatt3 posted this at 14:49 — 21st November 2006.
He has: 2,102 posts
Joined: Sep 2003
Ah, the pipe. Good idea.
Nope . We talked about if thens in class, but I didn't quite understand the syntax. So I wanted to create a simple script to help me better understand. It took me forever to figure out the difference between this=that and this = that. I guess whitespace does matter in more instances that I thought.
Thanks for the help again Abhishek. Did you learn *nix in a class setting like this, or on your own?
Abhishek Reddy posted this at 15:12 — 21st November 2006.
He has: 3,348 posts
Joined: Jul 2001
Yeah, it's really arcane. I avoid shell scripting with bash and co. whenever possible, unless it's a quick one-liner.
Not in a class setting, but not entirely on my own. Online documentation is indispensable.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.