gpt4 book ai didi

string - Bash:如何在一行中应用两个字符串操作?

转载 作者:行者123 更新时间:2023-11-29 08:59:34 25 4
gpt4 key购买 nike

我想立即更改变量中文件的路径和扩展名,例如执行以下操作

for F in $( find /foo/bar -name "*.ext" ); do 
Ftmp=${F%.ext}
cp $F ${Ftmp//bar/b0r}.tmp
done

没有临时变量

可以使用 bash only 方式同时应用两个字符串操作吗?

最佳答案

使用 Bash temporary variable

$_    Temporary variable; initialized to pathname of script or program
being executed. Later, stores the last argument of previous command.
Also stores name of matching MAIL file during mail checks.
for F in $( find /foo/bar -name "*.ext" )
do
: ${F%.ext}
cp $F ${_//bar/b0r}.tmp
done

关于string - Bash:如何在一行中应用两个字符串操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9099233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com