cut截取
-d 表示使用什么作为分割符,-f 表示截取的偏移。
#!/bin/bash
test_str="hello world and hello shell"
#使用空格作为分隔符,截取第1、2个字断
split=`echo $test_str | cut -d " " -f1,2`
echo $split # hello world
偏移截取
${split,n,m} n表示起始位置,m表示截取多少个字符
${split,n,} n表示起始位置,一直到字符串结束
#!/bin/bash
test_str="hello world and hello shell"
#使用空格作为分隔符,截取第1、2个字断
split=`echo $test_str | cut -d " " -f1,2`
#ello world
echo $split
#he
echo ${split:0:2}
#llo world
echo ${split:2}