获取在bash的最新目录到一个变量 [英] Get the newest directory in bash to a variables

查看:104
本文介绍了获取在bash的最新目录到一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到一个目录中最新的子目录,并将结果保存到变量在bash。

事情是这样的:

  LS -t /备份|头-1> $ BACKUPDIR

谁能帮助?


解决方案

  BACKUPDIR = $(LS -t /备份|头-1)

$(...)评估在子shell语句并返回输出。

I would like to find the newest sub directory in a directory and save the result to variable in bash.

Something like this:

ls -t /backups | head -1 > $BACKUPDIR

Can anyone help?

解决方案

BACKUPDIR=$(ls -t /backups | head -1)

$(...) evaluates the statement in a subshell and returns the output.

这篇关于获取在bash的最新目录到一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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