長度> 4如何提取在bash
str = "abcdefghijklmno"
一個子我有以下字符串中bash和欲提取到str2
的str
5第一charachter。所以
str2="abcde"
如何用bash做到這一點?
長度> 4如何提取在bash
str = "abcdefghijklmno"
一個子我有以下字符串中bash和欲提取到str2
的str
5第一charachter。所以
str2="abcde"
如何用bash做到這一點?
不要使用表達式
{string:position:length}
因此,在這種情況下:
$ str="abcdefghijklm"
$ echo "${str:0:5}"
abcde
見其他用途:
$ echo "${str:0}" # default: start from the 0th position
abcdefghijklm
$ echo "${str:1:5}" # start from the 1th and get 5 characters
bcdef
$ echo "${str:10:1}" # start from 10th just one character
k
$ echo "${str:5}" # start from 5th until the end
fghijklm
來自
- wooledge.org - How can I use parameter expansion? How can I get substrings? How can I get a file without its extension, or get just a file's extension?
- Shell Command Language - 2.6.2 Parameter Expansion
你可以使用'man bash'來查看這種類型的東西的命令列表 – user1527227 2014-07-02 02:43:10