[Bash] Backticks, xargs and Arithmetic

Backticks

Using to exec cmd and return the output as string

$ echo `date`
Fri Jun 7 15:40:11 EEST 2024

The same effect you can achieve by using

$ echo $(date)
Fri Jun 7 15:40:11 EEST 2024

Examples

$ echo `date +%F`
2024-06-07

$ echo some log data > blah-`date +%F`.log
# it creates log files blah-2024-06-07.log

arithmetic

With $((...)) expressions, you can do simple arithmetic on the command line.

$ echo $((4*5+1))
21

$ echo Greetings from the year $((`date +%Y`+1000))
Greetings from the year 3024

xargs

Read from stdin, and apply the result to next cmd, kind of like point free sytle.

$ date +%Y | xargs echo Grettings from the year
Greetings from the year 2024
posted @   Zhentiw  阅读(3)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2021-06-07 [AWS - DA] ECS, ECR, Fargate
2020-06-07 [Intro to Deep Learning with PyTorch -- L2 -- N9] Perceptron Trick
2020-06-07 [Javascript] Broadcaster, operator, listener pattern: Write a debounce operator -- 1
2019-06-07 [Nx] Generate Angular, React FE applications and Nest Backend with shared interfaces, utils libraries by Nx
2017-06-07 [TypeStyle] Load raw CSS in TypeStyle
2017-06-07 [TypeStyle] Use TypeStyle keyframes to create CSS animations
2017-06-07 [Node] Using dotenv to config env variables
点击右上角即可分享
微信分享提示