我怎样才能在使用bash字符串更改扩展名? [英] How can I change the extension name in a string with bash?

查看:101
本文介绍了我怎样才能在使用bash字符串更改扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要翻译下面的Python code打坏。在code更改扩展名以.html和运行Safari浏览器打开它。

 #!的/ usr /斌/包膜蟒蛇
进口os.path中
进口OS使用oldName = $ TM_FILEPATH
(姓名,分机)= os.path.splitext(使用oldName)
重命名=名+名.html
使用os.system(开放式野生动物园-a%的重命名%)

如何更改使用bash文件扩展名?


解决方案

 文件= somefile.whatevs
打开Safari浏览器-a$ {文件%。*} HTML

I want to translate the following python code to bash. The code changes the extension name to .html and runs Safari to open it.

#!/usr/bin/env python
import os.path
import os

oldName = $TM_FILEPATH
(name, ext) = os.path.splitext(oldName)
rename = name + ".html"
os.system("open -a Safari %s" % rename)

How can I change the file extension with bash?

解决方案

file=somefile.whatevs
open -a Safari "${file%.*}.html"

这篇关于我怎样才能在使用bash字符串更改扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆