多くの方法文字列シェルインターセプト
$ {#* /}だった $ {##でした* /} $ {VARの%/ *} $ {%% / *た} $ {ました:開始:LENを} $ {ました:出発} $ {ました:0-開始:LEN} $ {VAR:0開始}
次の例では、どのような数を示しています。
1)文字列の長さを求めます
構文:
$#{}ました
サンプルコード:
STR = "http://www.fengbohello.xin3e.com/blog/shell-truncating-string" エコー"列:[$ {STR}]" 長= $ {#列str} エコー「長さ:[$ {長さ} ]」
結果:
列:[http://www.fengbohello.xin3e.com/blog/shell-truncating-string] 長さ:[61]
2)#1 ##と末尾部分文字列を使用して取得
正面から撮影した2.1)#最小ワード
構文:
$ {パラメータ#ワード}
サンプルコード:
STR = "http://www.fengbohello.xin3e.com/blog/shell-truncating-string" エコー"の文字列:[$ {STR}]" #分割符为'/' のsubstr = $ {strの番号の* /} ":[$ {SUBSTR}] SUBSTR"エコー
結果:
文字列:[http://www.fengbohello.xin3e.com/blog/shell-truncating-string] SUBSTR:[/www.fengbohello.xin3e.com/blog/shell-truncating-string]
2.2)##を正面から撮影した最大ワード
構文:
$ {パラメータ##ワード}
サンプルコード:
STR = "http://www.fengbohello.xin3e.com/blog/shell-truncating-string" エコー"の文字列:[$ {STR}]" #分割符为'/' のsubstr = $ {strの## * / } エコー"SUBSTR:[$ {SUBSTR}]"
結果:
文字列:[http://www.fengbohello.xin3e.com/blog/shell-truncating-string] SUBSTR:[シェル切り捨てる文字列]
3)%%%ヘッドとサブストリングを取得します。
後ろから採取した3.1)%の最小ワード
構文:
$ {パラメータ%ワード}
サンプルコード:
STR = "http://www.fengbohello.xin3e.com/blog/shell-truncating-string" エコー"列:[$ {STR}]" SUBSTR = $ {STRの%/ *} エコー「SUBSTR:[$ { SUBSTR}]」
結果:
文字列:[http://www.fengbohello.xin3e.com/blog/shell-truncating-string] SUBSTR:[http://www.fengbohello.xin3e.com/blog]
3.2)の後ろから取ら%%単語を最大化
構文:
$ {パラメータ%%ワード}
サンプルコード:
STR = "http://www.fengbohello.xin3e.com/blog/shell-truncating-string" エコー"列:[$ {STR}]" SUBSTR = $ {STR %% / *} エコー「SUBSTR:[$ {SUBSTR}]」
結果:
文字列:[http://www.fengbohello.xin3e.com/blog/shell-truncating-string] SUBSTR:[HTTP:]
4)$ {VAR:}サブストリングを取得するモード
4.1)開始とストリングの最初の数文字の左からの文字数を指定します。
構文:
$ {Varの開始:LEN}
サンプルコード:
= STR「http://www.fengbohello.xin3e.com/blog/shell-truncating-string」 エコー「列:[STR $ {}]」 左側が最初の文字を表す#0、サブキャラクタ7つの意味総数の。 STR $ {= SUBSTR:0 :. 7は} ":[$ {SUBSTR}] SUBSTR"をエコー
結果:
文字列:[http://www.fengbohello.xin3e.com/blog/shell-truncating-string] SUBSTR:[のhttp://]
4.2)最初の数文字の左から終わりまで
構文:
$ {変数:7}
サンプルコード:
= STR "http://www.fengbohello.xin3e.com/blog/shell-truncating-string" エコー"列:[STR $ {}]" から始まる最初の8つの文字の左側を表す#7 のsubstr = $ {STR :7} エコー"SUBSTR:[$ {SUBSTR}]"
結果:
文字列:[http://www.fengbohello.xin3e.com/blog/shell-truncating-string] SUBSTR:[www.fengbohello.xin3e.com/blog/shell-truncating-string]
4.3)最初の数文字の最初の数文字の右側から
構文:
$ {変数:0スタート:LEN}
サンプルコード:
= STR「http://www.fengbohello.xin3e.com/blog/shell-truncating-string」 エコー「の文字列を[STR $ {}]」 #右側が23文字の開始日を表し0-23、 5文字の数を示す のsubstr = $ {STR:0-23:5} ":[$ {SUBSTR}] SUBSTR"エコー
結果:
文字列:[http://www.fengbohello.xin3e.com/blog/shell-truncating-string] SUBSTR:[シェル]
4.4)最後まで最初の数文字の右から始まります
構文:
$ {0}ブートました
サンプルコード:
= STR「http://www.fengbohello.xin3e.com/blog/shell-truncating-string」 エコー「の文字列を[STR $ {}]」 右辺第6文字がカウントを開始表す#0-6 SUBSTRをSTR $ {= 0-6} エコー"SUBSTR:[$ {SUBSTR}]"
結果:
文字列:[http://www.fengbohello.xin3e.com/blog/shell-truncating-string] SUBSTR:[文字列]