在shell中输出具有变量名的文件 [英] output a file with a variable name in shell

查看:160
本文介绍了在shell中输出具有变量名的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图输出一个文件,其名称类似于:lastlogin- yyyymmdd,其中包含当前日期。
我计算出日期应该是: date +%Y%m%d 我试图做一个变量

So I am trying to output a file with the name of like: lastlogin-"yyyymmdd" where it contains the current date. I figured out the date should be : date +"%Y%m%d" and I tried to do a variable

now =日期+ lastlogin-%Y%m%d.txt
文件名= $ {now}
xxxxx> $ {filename}

,但似乎没有任何作用

now = date +"lastlogin-%Y%m%d.txt" filename = ${now} xxxxx > ${filename} but nothing seems to work

请帮助

推荐答案

您应该使用 $()来执行命令并存储结果:

You should use $() for command execution and storage of result:

now=$(date +"lastlogin-%Y%m%d.txt")

这篇关于在shell中输出具有变量名的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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