#!/bin/bash
a="hello"
b="hi is $a"
echo $b
echo ${#a}
echo ${a}
echo ${a:1:2}
执行脚本方式不同出现的结果不同:
方式1:
sh shell.sh
hi is hello
5
hello
shell.sh: 7: shell.sh: Bad substitution
方式2:赋予shell.sh文件可执行权限,
./shell.sh
hi is hello
5
hello
el
方式3:bash shell.shhi is hello
5
hello
el
核心是要用/bin/bash