Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何将w输出重定向到$DATE命名的文件$TIME.users?
w
$DATE
$TIME.users
我有这个但不确定它是否有效:
w > $TIME.users
我在其中创建了一个目录.bash_login并调用了~/sysadmin1/my_peeps/$DATE.
.bash_login
~/sysadmin1/my_peeps/$DATE
另外,在里面.bash_login我创建了两个变量,它们是
DATE=$(date +"%m/%d/%y") TIME=$(date +"%H:%M:%S")
如果$TIME未设置,则该行变为
$TIME
w > .users
所以输出被重定向到一个隐藏.users文件。您可以使用ls -a.
.users
ls -a
另请注意,您需要导出变量bash以使其在子 shell 中可用:
bash
export TIME=$(date +"%H:%M:%S")