Give previous date as argument to shell script

7,134

With GNU date:

previousdate=$( date -d 'yesterday' +'%F' )
sh processFile.sh "$previousdate" "$previousdate"

With macOS date:

previousdate=$( date -j -v -1d +'%F' )
sh processFile.sh "$previousdate" "$previousdate"
Share:
7,134

Related videos on Youtube

user218332
Author by

user218332

Updated on September 18, 2022

Comments

  • user218332
    user218332 over 1 year

    I need to execute the script by passing previous date as command line argument. It must be automated. So, how can i pass the previous date to the script?

    For example:

    sh processFile.sh previousdate previousdate
    
    • Kusalananda
      Kusalananda over 5 years
      The correct answer may depend quite heavily on what type of Unix system this is for.