I'm new to shell scripting and wanted to insure I haven't made any errors in creating this script for making a borg backup to a flashdrive that I plug into my computer.

  • Does the below script look solid? (I made it executable and put it in my /usr/local/bin/)

  • I added the "date" command substitution within the "borg" command substitution. Is this allowed? Are there any rules that frown on putting command substitutions within command substitutions?

  • Does the entire line need quotes (") around it, like I have done?


echo "$(borg create /media/$USER/Flashdrive/backup::$(date +%FT%H%M) /home/$USER/Documents)"
  • The ability to be easily nested is one of the reasons often given for preferring this form of command substitution over the older "backtick" form. See for example What's the difference between $(stuff) and ` stuff `? Apr 19, 2020 at 1:00
  • The echo and the first command substitution are not needed (but the outer quotes around the command substitution would be correct). And borg allows a few placeholders in the archive name, so you could write the date as {now:%Y-%m-%dT%H%M} (maybe %F instead of %Y-%m-%d works too, I just haven't seen an example in the manual).
    – Freddy
    Apr 19, 2020 at 1:26
  • Why did you use curly braces: {now:%FT%M%H}. instead of $(now:%FT%M%H)?
    – user847
    Apr 19, 2020 at 14:19
  • Freddy, would you mind posting as an answer? If I understand you, you recommended this formatting: borg create /media/$USER/Flashdrive/backup::"$(date +%FT%H%M)" /home/$USER/Documents
    – user847
    Apr 19, 2020 at 14:25
  • Why are you using echo? Rather than echo $(borg …), why not just run the borg … command? Jul 30, 2020 at 20:54

1 Answer 1


This looks ok. You can easily try it by replacing borg with echo and see if this is what you are looking for.

Double quotes are not required.

  • Replace borg with echo? Like this: echo $(echo create /media...)
    – user847
    Apr 19, 2020 at 1:00
  • Yes, and you'll see the output right the way - without being afraid by whatever borg might do.
    – kosolapyj
    Apr 19, 2020 at 1:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .