Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [LINUX] Build fails with `/bin/sh: 1: Syntax error: "(" unexpected` when using shadow build outside project directory parent containing bracket "("
Forum Update on Monday, May 27th 2025

[LINUX] Build fails with `/bin/sh: 1: Syntax error: "(" unexpected` when using shadow build outside project directory parent containing bracket "("

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    huulong
    wrote on 27 Jan 2020, 16:18 last edited by
    #1

    This is a very edge case but it is also about the more general question of how to customize the shell used to build a Qt project on Linux.

    Repro

    1. Create a directory containing a bracket "(" or ")" in the name, such as "test (bracket)"
    2. Create a new Qt project inside this directory
    3. Go to Project Build Settings, check Shadow Build

    At this point, build works correctly, because everything happens inside "test (bracket)" so the g++ command can use the relative path ../TestBracket/main.cpp.

    2020-01 Qt build fail on path bracket 1 - original shadow build path.png
    2020-01 Qt build fail on path bracket 2 - build without error as relative path avoids bracket dir.png

    1. Still in Project Build Settings, under Shadow Build, change the Build directory to move one level up, by removing "test (bracket)"
    2. Build project

    Result: Build fails with /bin/sh: 1: Syntax error: "(" unexpected / ")" unexpected`

    This time, the g++ command needs to refer to ../test\ (bracket)/TestBracket/main.cpp

    2020-01 Qt build fail on path bracket 3 - shadow build path moved upward needs go down through backet dir.png
    2020-01 Qt build fail on path bracket 4 - build error as relative path needs to go through bracket dir.png

    Note that Qt projects cannot contain space/bracket in the name at creation time, but may after copying/renaming them. Actually I found this bug precisely after duplicating a project and adding brackets in the name (in which case the error happens even if the Shadow Build path is not moved one level above, as the project name itself would contain a bracket).

    Similar issues

    I only found https://forum.qt.io/topic/67061/error-from-bin-sh-when-compiling-under-linux to be similar, although it was failing due to a Windows path "Program Files (x86)", hence the brackets. This makes me think, by the way, that the order only happens on Linux, maybe OSX.

    Possible solution

    According to https://unix.stackexchange.com/questions/45781/shell-script-fails-syntax-error-unexpected, using env bash would allow the g++ command to recognize brackets in side double quotes, unlike sh. I don't see how to customize the shell in Qt on Linux, however.

    Workaround

    When using Shadow Build, do not put round brackets "(" nor ")" in any directory of your path to project; or at least, in any directory under where you'll put your Shadow Build.
    In my case, the path to project was rendering absolute for some reason, so I really needed it clean.

    Interestingly, I was checking if my .pro files were supporting spaces, but those were escaped correctly when using $$ without the need for extra double quotes. The g++ command, however, is very generic and doesn't really care about the content of .pro.

    A 1 Reply Last reply 27 Jan 2020, 17:55
    2
    • H huulong
      27 Jan 2020, 16:18

      This is a very edge case but it is also about the more general question of how to customize the shell used to build a Qt project on Linux.

      Repro

      1. Create a directory containing a bracket "(" or ")" in the name, such as "test (bracket)"
      2. Create a new Qt project inside this directory
      3. Go to Project Build Settings, check Shadow Build

      At this point, build works correctly, because everything happens inside "test (bracket)" so the g++ command can use the relative path ../TestBracket/main.cpp.

      2020-01 Qt build fail on path bracket 1 - original shadow build path.png
      2020-01 Qt build fail on path bracket 2 - build without error as relative path avoids bracket dir.png

      1. Still in Project Build Settings, under Shadow Build, change the Build directory to move one level up, by removing "test (bracket)"
      2. Build project

      Result: Build fails with /bin/sh: 1: Syntax error: "(" unexpected / ")" unexpected`

      This time, the g++ command needs to refer to ../test\ (bracket)/TestBracket/main.cpp

      2020-01 Qt build fail on path bracket 3 - shadow build path moved upward needs go down through backet dir.png
      2020-01 Qt build fail on path bracket 4 - build error as relative path needs to go through bracket dir.png

      Note that Qt projects cannot contain space/bracket in the name at creation time, but may after copying/renaming them. Actually I found this bug precisely after duplicating a project and adding brackets in the name (in which case the error happens even if the Shadow Build path is not moved one level above, as the project name itself would contain a bracket).

      Similar issues

      I only found https://forum.qt.io/topic/67061/error-from-bin-sh-when-compiling-under-linux to be similar, although it was failing due to a Windows path "Program Files (x86)", hence the brackets. This makes me think, by the way, that the order only happens on Linux, maybe OSX.

      Possible solution

      According to https://unix.stackexchange.com/questions/45781/shell-script-fails-syntax-error-unexpected, using env bash would allow the g++ command to recognize brackets in side double quotes, unlike sh. I don't see how to customize the shell in Qt on Linux, however.

      Workaround

      When using Shadow Build, do not put round brackets "(" nor ")" in any directory of your path to project; or at least, in any directory under where you'll put your Shadow Build.
      In my case, the path to project was rendering absolute for some reason, so I really needed it clean.

      Interestingly, I was checking if my .pro files were supporting spaces, but those were escaped correctly when using $$ without the need for extra double quotes. The g++ command, however, is very generic and doesn't really care about the content of .pro.

      A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 27 Jan 2020, 17:55 last edited by
      #2

      Hi @huulong,

      very nicely summed up!

      I've already created QTCREATORBUG-20834 some time ago, and your case fits perfectly there.

      You may comment and vote on that bug, so we at least get a warning from the IDE.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      1
      • H Offline
        H Offline
        huulong
        wrote on 27 Jan 2020, 20:10 last edited by
        #3

        Thanks, I voted up for the warning suggestion.

        1 Reply Last reply
        1

        1/3

        27 Jan 2020, 16:18

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved