Shell脚本中的循环

字符串的拼接与分割

Posted by Xuan on December 9, 2021

Shell中字符串拼接

1.直接‘’组合字符串

a='files''.fasta'
echo $a

a='hi'
b=$a'.bed'
echo $b

2.变量拼接

str1='hello'
str2='world'
str3=$str1$str2
echo $str3
str1='hello'
str2='world'
str3="$str1, $str2 !"
echo $str3

3.linux命令拼接

# 命令
str1=`date`
# 当前日期
echo $str1

str2="current date is: "`date`
echo $str2

TIPS: ‘’ 与 “”区别: 单引号内命令不执行;双引号内命令执行

str04="`date`"
echo ${str04}
str05='`date`'
echo ${str05}

Shell中字符串分割

Reference

分割1 分割2

paste - - - (连续三行变为一行)