0

I have a script to output git commits with specific jira ticket and within a date and time range, however i keep hitting an error, my codes are below:

SINCE="2021-02-26 17:59:58"
BEFORE="2021-03-05 17:59:58"
CMD="git log -p -m -name-status --since=\"${SINCE}\" --before=\"${BEFORE}\" --grep=${TICKET}
${CMD} >> out.txt

Error:

Fatal: Invalid object name '17'

I tried enclosing the cmd with "" "${CMD}" also getting same error. Anyone know what is wrong with it?

skyzhuzhu
  • 45
  • 1
  • 8
  • Don't store commands in string variables. See [BashFAQ #50](https://mywiki.wooledge.org/BashFAQ/050). – Charles Duffy Mar 05 '21 at 16:09
  • ...and note that the answers in the linked duplicates suggesting `eval` introduce security bugs (unless precautions those answers don't currently describe are taken) and should be avoided, in favor of those answers suggesting arrays. [BashFAQ #48](https://mywiki.wooledge.org/BashFAQ/048) goes into more details re: the security exposure. – Charles Duffy Mar 05 '21 at 16:12
  • 1
    (Not related to your issue, but note that it's better to use lowercase names for your own variables; all-uppercase names are reserved for variables that have special meaning to the shell and OS-provided tools -- see https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html; "*The name space of environment variable names containing lowercase letters is reserved for applications. Applications can define any environment variables with names from this name space without modifying the behavior of the standard utilities.*") – Charles Duffy Mar 05 '21 at 16:16
  • (...read the above standard document keeping in mind that setting a regular shell variable will overwrite any environment variable having the same name, so to properly avoid overwriting environment variables with names in reserved space, one _also_ needs to keep shell variable names out of the reserved space). – Charles Duffy Mar 05 '21 at 16:18

0 Answers0