jira-cli icon indicating copy to clipboard operation
jira-cli copied to clipboard

using "jira issue list --plain -q ..." in a bash script producess weird errors

Open bazulay opened this issue 3 years ago • 2 comments

Describe the bug

total 8
drwxrwxr-x. 1 guest guest   32 May 22 13:44 .
drwxrwxr-x. 1 guest guest 1480 May 22 13:43 ..
-rwxr-xr-x. 1 guest guest  122 May 22 13:44 test-jira-cli.sh
[guest@home tmp]$ cat test-jira-cli.sh 
#!/bin/sh

QUERY="fixVersion = Elektra"

CMD="jira issue list --plain -q \"${QUERY}\""
echo "[${CMD}]"

$($CMD $QUERY)
  
[guest@home tmp]$ 
[guest@home tmp]$ ./test-jira-cli.sh 
[jira issue list --plain -q "fixVersion = Elektra"]

Error:
  - Error in the JQL Query: The quoted string 'fixVersion ORDER BY created DESC' has not been completed. (line 1, character 19)

jira: Received unexpected response '400 Bad Request'.
Please check the parameters you supplied and try again
[guest@home tmp]$

As you can see the query does not contain "ORDER BY ..."

Please provide following details

  1. JiraCLI Version:
    Please paste the output of `jira version` here.
    
  2. Are you using Jira cloud or on-premise jira server? Also mention the version for on-premise installation.
    (Version="main", GitCommit="90453390acd100cd5c438882fbe21cb479a25362", CommitDate="2022-05-12T15:27:37+00:00", GoVersion="go1.16.15", Compiler="gc", Platform="linux/amd64")
    
  3. What operating system are you using? Also mention version.
    Fedora release 35 (Thirty Five)
    
  4. What terminal are you using? Also mention version.
    GNOME Terminal Version 3.42.2 for GNOME 41
    

To Reproduce

simply run the adjusted above script (change the query to fit your project)

Expected behavior

jira-cli should run the query

bazulay avatar May 22 '22 11:05 bazulay

Hi @bazulay, I think the problem here is because of word splitting.

The ultimate goal is to run following query from the shell script

jira issue list --plain -q "fixVersion = Elektra"

But the script you shared above will execute something like below causing the issue

jira issue list --plain -q \"fixVersion = Elektra\"

Something like this should work.

#!/bin/sh

QUERY="fixVersion = Elektra"

OUT=$(jira issue list --plain -q "$QUERY")

echo $OUT

ankitpokhrel avatar May 22 '22 19:05 ankitpokhrel

@bazulay your shell quoting is wrong. If you're going to store commands as shell-quoted strings, then consider https://www.etalabs.net/sh_tricks.html, specifically the section on "Shell-quoting arbitrary strings".

realtime-neil avatar May 23 '22 13:05 realtime-neil

Closing due to inactivity

ankitpokhrel avatar Aug 14 '22 16:08 ankitpokhrel