1

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?

#!/bin/bash

echo "$(borg create /media/$USER/Flashdrive/backup::$(date +%FT%H%M) /home/$USER/Documents)"
NickD
  • 2,866
  • 1
  • 10
  • 21
user847
  • 111
  • 1
  • 1
  • 2
  • 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 `?](https://unix.stackexchange.com/questions/5778/whats-the-difference-between-stuff-and-stuff) – steeldriver Apr 19 '20 at 01: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](https://borgbackup.readthedocs.io/en/stable/usage/create.html)). – Freddy Apr 19 '20 at 01:26
  • Why did you use curly braces: {now:%FT%M%H}. instead of $(now:%FT%M%H)? – user847 Apr 19 '20 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 '20 at 14:25
  • Why are you using `echo`? Rather than ``echo $(borg …)``, why not just run the `borg …` command? – G-Man Says 'Reinstate Monica' Jul 30 '20 at 20:54

1 Answers1

0

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.

kosolapyj
  • 16
  • 1