5 ms·
Hang out in #bash on IRC Freenode and you will be a Bash jedi http://mywiki.wooledge.org/BashFAQ http://mywiki.wooledge.org/BashFAQ best resource IMO for quick
by joshbaptiste 9y ago
Hang out in #bash on IRC Freenode and you will be a Bash jedi http://mywiki.wooledge.org/BashFAQ http://mywiki.wooledge.org/BashFAQ best resource IMO for quick Bash syntax lookups as I always need to refer to the BashFaq to remember parameter expansion sub-string retrieval.
parameter result
----------- ------------------------------
$name polish.ostrich.racing.champion
${name#*.} ostrich.racing.champion
${name##*.} champion
${name%%.*} polish
${name%.*} polish.ostrich.racing
- ZenoArrow 9y agoExtending your example above, how would you get a result of racing.champion or polish.ostrich ?
- Xophmeister 9y agoYou'd have to do it twice, using a temporary variable: $ name="polish.ostrich.racing.champion" $ temp="${name#*.}" $ echo "${temp#*.}" racing.champion That's if you want it generic (i.e., splitting on "." characters). In one shot, you could make the pattern more specific: $ echo "${name#*ostrich.}" racing.champion ...or use something like sed or awk: $ awk 'BEGIN {FS=OFS="."} {print $(NF-1), $NF}' <<< "${name}" racing.champion
- mbudde 9y ago${name%.*.*} polish.ostrich ${name#*.*.} racing.champion
- itwy 9y agoThey are needlessly rude and mean at #bash. A bunch of scumbags, actually.
- jakeogh 9y agoComplete opposite of my experience.
- LambdaComplex 9y agoI think it's a result of constantly dealing with people who ask for help, receive good advice, and then ignore it
- viraptor 9y agoIf that annoys then, they can always quit. Being rude in this situation is either a choice or lack of ability to cope with stress. Neither excuses being rude...