在bash中将前缀和后缀添加到$ @ [英] Add prefix and suffix to $@ in bash
本文介绍了在bash中将前缀和后缀添加到$ @的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在$@
上添加后缀和前缀?
How to add suffix and prefix to $@
?
如果执行$PREFIX/$@/$SUFFIX
,则仅在第一个参数中获得前缀和后缀.
If I do $PREFIX/$@/$SUFFIX
, I get the prefix and the suffix only in the first parameter.
推荐答案
I would use shell [ parameter expansion ] for this
$ set -- one two three
$ echo "$@"
one two three
$ set -- "${@/#/pre}" && set -- "${@/%/post}"
$ echo "$@"
preonepost pretwopost prethreepost
注释
-
#
与开头匹配 -
%
与结尾匹配 - 在
${@}
周围使用双引号会将每个元素视为一个单独的单词.因此替换发生在每个位置参数上
- The
#
matches the beginning - The
%
matches the end - Using double quotes around
${@}
considers each element as a separate word. so replacement happens for every positional parameter
这篇关于在bash中将前缀和后缀添加到$ @的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文