-1

The below command works in command line

rsync -avh -r /Source/09_03_2016/ /Destination/
echo $(basename !:3)

Output 09_03_2016

But when I do this in shell script it does not work

#! /bin/bash

/usr/bin/rsync -avh -r /Source/09_03_2016 /Destination/;
echo $(basename !:3)

Output !:3

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
HDev007
  • 261
  • 1
  • 4
  • 10

1 Answers1

5

Use the following directives in your script:

set -o history
set -o histexpand

This will enable the history expansion which is only enabled for interactive shells by default.

See man bash section HISTORY EXPANSION and SHELL BUILTIN COMMANDS command set for details.

Lambert
  • 12,495
  • 2
  • 26
  • 35