[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
分类:
CLI
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源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