从右侧提取两个/之间的字符串
命令准备:
输入:-[目录名不是常量]
例1:
/dir1/dir2/
例2:
/dir1/dir2/dir3/dir4/
我要输出如下
示例1输出:
nohup dsmc arch /dir1/dir2/ -subdir=yes > /tsm/backuplogs/dir2_`date +%d%m%y_%H_%M`.log &
示例2输出:
nohup dsmc arch /dir1/dir2/dir3/dir4/ -subdir=yes > /tsm/backuplogs/dir4_`date +%d%m%y_%H_%M`.log &
最佳答案
使用basename
程序从路径中提取最后一个目录,如下所示:
path=/dir1/dir2/dir3/dir4/
echo "nohup dsmc arch $path -subdir=yes > /tsm/backuplogs/$(basename $path)_\`date +%d%m%y_%H_%M\`.log &"
上述行将输出:
nohup dsmc arch /dir1/dir2/dir3/dir4/ -subdir=yes > /tsm/backuplogs/dir4_`date +%d%m%y_%H_%M`.log &
关于linux - 从右提取两个/之间的字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29092293/