我正在将文件的最后一行读入变量。然后我想获取字符串变量的最后 X 个字符:
#!/bin/bash
someline="this is the last line content"
echo ${someline}
somepart=${someline: -5}
echo ${somepart}
Run Code Online (Sandbox Code Playgroud)
运行: sh lastchars.sh
结果:
this is the last line content
line 4: Bad substitution
Run Code Online (Sandbox Code Playgroud)
这里可能有什么问题?
bash ×1