在Ash shell(BusyBox)中,可以使用以下代码示例来检查文件扩展名:
#!/bin/ash
# 获取文件名及其扩展名
filename="example.txt"
extension="${filename##*.}"
# 检查文件扩展名
if [ "$extension" = "txt" ]; then
echo "文件扩展名为txt"
else
echo "文件扩展名不为txt"
fi
上述代码中,我们首先定义了一个文件名 example.txt
,然后使用 ${filename##*.}
来获取文件的扩展名。接下来,我们使用条件判断语句来检查文件扩展名是否为 txt
,并输出对应的结果。
注意:在Ash shell中,#!/bin/ash
是指定解释器的声明,确保你的脚本中包含这一行。