当前第2页 返回上一页
最后在一个shell脚本中测试所有内容。使用以下内容创建新的脚本文件。在执行脚本期间,文件名将作为命令行参数传递。
1 2 3 4 5 6 7 8 9 10 11 | #!/bin/bash
fullfilename=$1
filename=$(basename "$fullfilename" )
fname= "${filename%.*}"
ext= "${filename##*.}"
echo "Input File: $fullfilename"
echo "Filename without Path: $filename"
echo "Filename without Extension: $fname"
echo "File Extension without Name: $ext"
|
我们以文件名作为命令行参数来执行脚本。
1 2 3 4 5 6 | $ ./script.sh /etc/apache2/apache2.conf
Input File: /etc/apache2/apache2.conf
Filename without Path: apache2.conf
Filename without Extension: apache2
File Extension without Name : conf
|
本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注PHP中文网的Linux教程视频栏目!
以上就是如何在Shell脚本中提取文件名和扩展名的详细内容,更多文章请关注木庄网络博客!
返回前面的内容
相关阅读 >>
linux终端执行shell脚本时提示权限不足
shell编程实战之内存检查超过设定值杀死php-fpm进程
一文读懂shell编程三剑客之一的sed命令
shell脚本高级编程的详细讲解
linux默认使用的shell是什么
linux shell中的curl和wget如何使用代理ip的方法教程
什么是posix shell
linux默认的shell是什么
shell编程实战之执行多个目录下的php程序
如何在shell脚本中以隐藏字符的形式输入密码
更多相关阅读请进入《shell》频道 >>
转载请注明出处:木庄网络博客 » 如何在Shell脚本中提取文件名和扩展名