Created
October 4, 2012 04:10
-
-
Save bluebruce/3831421 to your computer and use it in GitHub Desktop.
shell/parse string with token. #ifs #shift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| snippets() | |
| { | |
| # Parse e_vw_v_scale_${VW_VAR_V_SCALE} | |
| # The token is '_' | |
| _IFS="$IFS";IFS='_';set -- $*;IFS="$_IFS" | |
| # Save the result | |
| VW_VAR_V_SCALE=$5 | |
| } | |
| explain() | |
| { | |
| # 把舊的 $IFS 存起來 | |
| _IFS="$IFS" | |
| # 設定 parse 的 token 為 '_' | |
| IFS='_' | |
| # 用 $IFS 來 parse $*, 結果會存在 $0, $1, $2..... | |
| set -- $* | |
| # 將 $IFS 設回 | |
| IFS="$_IFS" | |
| # 抓取要的結果, 如 $5 | |
| parsed_result=$5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment