以下命令在命令行中有效
rsync -avh -r /Source/09_03_2016/ /Destination/
echo $(basename !:3)
输出09_03_2016
但是当我在shell脚本中执行此操作时,它不起作用
#! /bin/bash
/usr/bin/rsync -avh -r /Source/09_03_2016 /Destination/;
echo $(basename !:3)
输出!:3
在脚本中使用以下指令:
set -o history
set -o histexpand
这将启用历史记录扩展,默认情况下仅对交互式Shell启用历史记录扩展。
有关详细信息,请参见man bash
部分HISTORY EXPANSION
和SHELL BUILTIN COMMANDS
命令set
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句