|
Bash ScriptingClass length: 18 weeks. Start anytime. Creator: kday Status: Established |
|
Assignment 1: Problem set 1Do all of the examples throughout Chapter 5 in Bash Cookbook by O'Reilly. To submit the homework, just leave a comment saying that you completed it and mention any problems you had or any cool things you learned. Don't print out your whole session history, it gets really long really fast. Do post code specific examples that you want to discuss. If you copy and paste any of your bash history, make sure that you don't post anything sensitive. Create dummy directories for working with files, don't post any passwords, etc. The assignment should take about 45 minutes to an hour to complete. Homework Submissions (3 total):it was straightforward except for the 4th pattern in table 5-1 of problem 5.18. name##pattern > O="i am bad"
> echo ${O##a}
> i am bad
but i am expecting > d (just d, since it is what's left after the longest front-anchored pattern has been removed)
Permalink
Useful chapter. It's complicated to keep track of the different ways that parameters can be parsed. Now I see why a cookbook is a useful format for bash. Lots of syntax gotchas. String manipulation operators are cool, but seem hard to remember also. No comments. Sign up or log in to comment |
Comments:
7 months ago
Yeah, I found that a little confusing also. The
##and%%seemed to make more sense when using a wildcard pattern instead of an exact match. See what I tried below.In your example, I think it returns the full string because your string begins with
iand it's trying to match something that begins witha. That's not how I thought it would behave but I think that's what it's doing.> MYSTR=hellohellobyebye > echo ${MYSTR#*o} hellobyebye > echo ${MYSTR##*o} byebyeSign up or log in to comment