Bash 4.4提示转义当前正在运行的作业数 [英] Bash 4.4 prompt escape for number of jobs currently running

查看:104
本文介绍了Bash 4.4提示转义当前正在运行的作业数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了这篇文章其中用户 chepner 在他的答案中提出了\j的用法(如

I stumbled across this post where user chepner proposed in his answer the usage of \j (as mentioned in the bash manual) to retrieve the current running count of background jobs. Basically it boils down to

num_jobs="\j"
echo ${num_jobs@P}

有人能启发我这里发生了什么吗?例如.

Can anyone enlighten me on what is going on here exactly? E.g.

  • 为什么${\j@P}无法正常工作
  • @P到底在做什么?
  • why ${\j@P} is not working and
  • what @P is doing exactly?

推荐答案

就像任何参数扩展一样,您必须提供参数名称,而不是任意字符串. \j不是参数名称;这是您要从参数扩展中获取 的文本.

Like any parameter expansion, you have to supply the name of a parameter, not an arbitrary string. \j isn't the name of a parameter; it's the text you want to get from a parameter expansion.

扩展参数后,@P进一步对结果进行迅速扩展,以便将\j替换为作业数.

After the parameter has been expanded, @P further subjects the result to prompt expansion, so that \j is replaced by the number of jobs.

$ num_jobs="\j"
$ echo "${num_jobs}"
\j
$ echo "${num_jobs@P}"
0

这篇关于Bash 4.4提示转义当前正在运行的作业数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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