Shell复制文件但更改扩展名

Shell复制文件但更改扩展名,shell,unix,sh,Shell,Unix,Sh,我对linux和shell非常陌生,我想将一个文件复制到一个参数传递的位置,但是更改它的扩展名,它的windows版本是 copy .\a\b\c.pre %~dpn2.i d --> get the drive letter only p --> get the path only n --> get the file name only 所以我的问题是:如何获得通过参数传递的文件的完整路径并向其添加文件扩展名 shell命令看起来像cp./a/

我对linux和shell非常陌生,我想将一个文件复制到一个参数传递的位置,但是更改它的扩展名,它的windows版本是

copy .\a\b\c.pre %~dpn2.i

    d --> get the drive letter only
    p --> get the path only
    n --> get the file name only

所以我的问题是:如何获得通过参数传递的文件的完整路径并向其添加文件扩展名

shell命令看起来像
cp./a/b/c.pre[$2 path,但扩展名为.i]

提前谢谢

for file in *.src; do
    cp "${file}" "${tgt_dir}"/"${file/%.src/.tgt}"
done

这将简单地将源文件夹中扩展名为.src的所有文件重命名为目标文件夹中的.tgt。您需要在脚本中设置目标文件夹

如果要复制文件并更改扩展名,为什么不简单地使用cp/path/c.pre/path/c.i?@JazzCat,因为该文件必须具有在argsThanks中传递的特殊名称,但如何从参数中提取目标目录?传递的参数类似于
/dev/sda1/a/b/c.XXX
,我想将文件复制到
/dev/sda1/a/b/c.I