Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ide wrapper bash script failing: #254

Closed
hohwille opened this issue Mar 18, 2024 · 7 comments · Fixed by #255, #257 or #259
Closed

ide wrapper bash script failing: #254

hohwille opened this issue Mar 18, 2024 · 7 comments · Fixed by #255, #257 or #259
Assignees
Labels
bash bug Something isn't working windows specific for Microsoft Windows OS

Comments

@hohwille
Copy link
Member

Expected behavior

As a IDEasy user, I want to set my environment variables using ide command so that I can work as simple as with devon CLI.

Actual behavior

$ ide
/d/projects/IDEasy/test/bin/ide: eval: line 22: syntax error near unexpected token `('

Steps to reproduce (bug) / Use Case of feature request (enhancement)

  1. run ide wrapper script

Related/Dependent Issues

Comments/Hints:

According to my analysis the error seems to come from path entries with Program Files (x86).
My assumption is that we need to double quote the variable values at least for bash.

Affected version:

  • OS: Windows
  • latest SNAPSHOT of IDEasy.
@hohwille hohwille added bug Something isn't working windows specific for Microsoft Windows OS bash labels Mar 18, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in IDEasy board Mar 18, 2024
@hohwille
Copy link
Member Author

There is another bug in the ide wrapper script.

This looks good:

$ ideasy.exe env
export PATH=D:\projects\IDEasy\software\jmc;D:\projects\IDEasy\software\node;D:\projects\IDEasy\software\java\bin;D:\projects\IDEasy\software\mvn\bin;D:\projects\IDEasy\software\az\bin;D:\projects\IDEasy\software\intellij\bin;D:\projects\IDEasy\software\aws;D:\projects\IDEasy\software\eclipse;C:\Users\hohwille\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\opt\bin;D:\oracle-xe\product\18.0.0\dbhomeXE\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\GnuPG\bin;C:\Program Files\SlikSvn\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Git\cmd;C:\Program Files\Rancher Desktop\resources\resources\win32\bin;C:\Program Files\Rancher Desktop\resources\resources\linux\bin;C:\Users\hohwille\scripts;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
MVN_VERSION=3.9.5
INTELLIJ_VERSION=2023.3.2
ECLIPSE_VERSION=2023-09
export AWS_SHARED_CREDENTIALS_FILE=D:\projects\IDEasy\conf\aws\credentials
IDE_HOME=D:/projects/IDEasy
DOTNET_VERSION=6*
NODE_VERSION=v18*
export AWS_CONFIG_FILE=D:\projects\IDEasy\conf\aws\config
export AZURE_CONFIG_DIR=D:\projects\IDEasy\conf\.azure
PYTHON_VERSION=3.11*
WORKSPACE=main
WORKSPACE_PATH=D:/projects/IDEasy/workspaces/main
JAVA_VERSION=blablabla
HOME=C:/Users/hohwille
export PATH=D:\projects\IDEasy\software\jmc;D:\projects\IDEasy\software\node;D:\projects\IDEasy\software\java\bin;D:\projects\IDEasy\software\mvn\bin;D:\projects\IDEasy\software\az\bin;D:\projects\IDEasy\software\intellij\bin;D:\projects\IDEasy\software\aws;D:\projects\IDEasy\software\eclipse;C:\Users\hohwille\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\opt\bin;D:\oracle-xe\product\18.0.0\dbhomeXE\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\GnuPG\bin;C:\Program Files\SlikSvn\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Git\cmd;C:\Program Files\Rancher Desktop\resources\resources\win32\bin;C:\Program Files\Rancher Desktop\resources\resources\linux\bin;C:\Users\hohwille\scripts;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl

But this does not:

$ echo $(ideasy.exe env)
export PATH=D:\projects\IDEasy\software\jmc;D:\projects\IDEasy\software\node;D:\projects\IDEasy\software\java\bin;D:\projects\IDEasy\software\mvn\bin;D:\projects\IDEasy\software\az\bin;D:\projects\IDEasy\software\intellij\bin;D:\projects\IDEasy\software\aws;D:\projects\IDEasy\software\eclipse;C:\Users\hohwille\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\opt\bin;D:\oracle-xe\product\18.0.0\dbhomeXE\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\GnuPG\bin;C:\Program Files\SlikSvn\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Git\cmd;C:\Program Files\Rancher Desktop\resources\resources\win32\bin;C:\Program Files\Rancher Desktop\resources\resources\linux\bin;C:\Users\hohwille\scripts;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl MVN_VERSION=3.9.5 INTELLIJ_VERSION=2023.3.2 ECLIPSE_VERSION=2023-09 export AWS_SHARED_CREDENTIALS_FILE=D:\projects\IDEasy\conf\aws\credentials IDE_HOME=D:/projects/IDEasy DOTNET_VERSION=6* NODE_VERSION=v18* export AWS_CONFIG_FILE=D:\projects\IDEasy\conf\aws\config export AZURE_CONFIG_DIR=D:\projects\IDEasy\conf\.azure PYTHON_VERSION=3.11* WORKSPACE=main WORKSPACE_PATH=D:/projects/IDEasy/workspaces/main JAVA_VERSION=blablabla HOME=C:/Users/hohwille export PATH=D:\projects\IDEasy\software\jmc;D:\projects\IDEasy\software\node;D:\projects\IDEasy\software\java\bin;D:\projects\IDEasy\software\mvn\bin;D:\projects\IDEasy\software\az\bin;D:\projects\IDEasy\software\intellij\bin;D:\projects\IDEasy\software\aws;D:\projects\IDEasy\software\eclipse;C:\Users\hohwille\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\opt\bin;D:\oracle-xe\product\18.0.0\dbhomeXE\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\GnuPG\bin;C:\Program Files\SlikSvn\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Git\cmd;C:\Program Files\Rancher Desktop\resources\resources\win32\bin;C:\Program Files\Rancher Desktop\resources\resources\linux\bin;C:\Users\hohwille\scripts;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl

So it seems we are loosing the newlines of the output if we send it into a variable.
This will not work. Piping it to eval can also not work as this will set the environment variables of a sub-process that then immediately exists and so it has no effect.

@hohwille
Copy link
Member Author

Was auto-closed by PR #255 but not all problems solved so reopening.

@hohwille hohwille reopened this Mar 19, 2024
@github-project-automation github-project-automation bot moved this from ✅ Done to 📋 Backlog in IDEasy board Mar 19, 2024
@hohwille
Copy link
Member Author

@aBega2000 got a different error than me. Something like this

/d/projects/IDEasy/test/bin/ide: eval: line 22: C:\projects\IDEasy\software\java\bin: is a directory

@hohwille
Copy link
Member Author

For the newlines it is as simple as this:
https://stackoverflow.com/questions/22101778/how-to-preserve-line-breaks-when-storing-command-output-to-a-variable

So:

$ echo $(ideasy env --bash)
export PATH=/d/projects/IDEasy/software/jmc;D:/projects/IDEasy/software/node;D:/projects/IDEasy/software/java/bin;D:/projects/IDEasy/software/mvn/bin;D:/projects/IDEasy/software/az/bin;D:/projects/IDEasy/software/intellij/bin;D:/projects/IDEasy/software/sonar/bin;D:/projects/IDEasy/software/aws;D:/projects/IDEasy/software/eclipse;C:/Users/hohwille/bin;C:/Program Files/Git/usr/local/bin;C:/Program Files/Git/usr/bin;C:/Program Files/Git/usr/bin;C:/Program Files/Git/opt/bin;D:/oracle-xe/product/18.0.0/dbhomeXE/bin;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/WINDOWS/System32/WindowsPowerShell/v1.0;C:/WINDOWS/System32/OpenSSH;C:/Program Files (x86)/GnuPG/bin;C:/Program Files/SlikSvn/bin;C:/Program Files/TortoiseSVN/bin;C:/Program Files/Git/cmd;C:/Program Files/Rancher Desktop/resources/resources/win32/bin;C:/Program Files/Rancher Desktop/resources/resources/linux/bin;C:/Users/hohwille/scripts;C:/Program Files/Git/usr/bin/vendor_perl;C:/Program Files/Git/usr/bin/core_perl MVN_VERSION=3.9.5 INTELLIJ_VERSION=2023.3.2 ECLIPSE_VERSION=2023-09 export AWS_SHARED_CREDENTIALS_FILE=/d/projects/IDEasy/conf/aws/credentials IDE_HOME=D:/projects/IDEasy DOTNET_VERSION=6* NODE_VERSION=v18* export AWS_CONFIG_FILE=/d/projects/IDEasy/conf/aws/config export AZURE_CONFIG_DIR=/d/projects/IDEasy/conf/.azure PYTHON_VERSION=3.11* WORKSPACE=main WORKSPACE_PATH=D:/projects/IDEasy/workspaces/main JAVA_VERSION=blablabla HOME=C:/Users/hohwille

But:

$ echo "$(ideasy env --bash)"
export PATH=/d/projects/IDEasy/software/jmc;D:/projects/IDEasy/software/node;D:/projects/IDEasy/software/java/bin;D:/projects/IDEasy/software/mvn/bin;D:/projects/IDEasy/software/az/bin;D:/projects/IDEasy/software/intellij/bin;D:/projects/IDEasy/software/sonar/bin;D:/projects/IDEasy/software/aws;D:/projects/IDEasy/software/eclipse;C:/Users/hohwille/bin;C:/Program Files/Git/usr/local/bin;C:/Program Files/Git/usr/bin;C:/Program Files/Git/usr/bin;C:/Program Files/Git/opt/bin;D:/oracle-xe/product/18.0.0/dbhomeXE/bin;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/WINDOWS/System32/WindowsPowerShell/v1.0;C:/WINDOWS/System32/OpenSSH;C:/Program Files (x86)/GnuPG/bin;C:/Program Files/SlikSvn/bin;C:/Program Files/TortoiseSVN/bin;C:/Program Files/Git/cmd;C:/Program Files/Rancher Desktop/resources/resources/win32/bin;C:/Program Files/Rancher Desktop/resources/resources/linux/bin;C:/Users/hohwille/scripts;C:/Program Files/Git/usr/bin/vendor_perl;C:/Program Files/Git/usr/bin/core_perl
MVN_VERSION=3.9.5
INTELLIJ_VERSION=2023.3.2
ECLIPSE_VERSION=2023-09
export AWS_SHARED_CREDENTIALS_FILE=/d/projects/IDEasy/conf/aws/credentials
IDE_HOME=D:/projects/IDEasy
DOTNET_VERSION=6*
NODE_VERSION=v18*
export AWS_CONFIG_FILE=/d/projects/IDEasy/conf/aws/config
export AZURE_CONFIG_DIR=/d/projects/IDEasy/conf/.azure
PYTHON_VERSION=3.11*
WORKSPACE=main
WORKSPACE_PATH=D:/projects/IDEasy/workspaces/main
JAVA_VERSION=blablabla
HOME=C:/Users/hohwille

So for this nothing needs to be done as @aBega2000 already quoted the variable correctly here:

eval "$ide_env"

@mvomiero
Copy link
Contributor

If I understood correctly, when running ide env, the current problem is that we get export PATH=/c/Program Files/Git/usr/bin... instead of export PATH="/c/Program Files/Git/usr/bin... (the " is missinig).

A way to solve that could be this, in EnvironmentCommandlet ?

  public void run() {

    Collection<VariableLine> variables = this.context.getVariables().collectVariables();
    for (VariableLine line : variables) {
      if (this.context.getSystemInfo().isWindows()) {
        line = normalizeWindowsValue(line);
+        if (line.getName().equals("PATH")) {
+         String lineValue = '"' + line.getValue() + '"';
+         line = line.withValue(lineValue);
        }
      }
      this.context.info(line.toString());
    }
  }

it solves the problem when running ide env, but I actually don't know if it is the right place or way to change it for our release 🌷

VinceHeu added a commit to VinceHeu/IDEasy that referenced this issue Mar 20, 2024
VinceHeu added a commit to VinceHeu/IDEasy that referenced this issue Mar 20, 2024
@VinceHeu
Copy link
Contributor

2 Questions:
Should we add the quotation marks:
-only for windows or for every os?
-only for path or for every variable?

@VinceHeu VinceHeu moved this from 📋 Backlog to 🏗 In progress in IDEasy board Mar 20, 2024
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in IDEasy board Mar 21, 2024
@hohwille
Copy link
Member Author

The quotes new appear and the ide wrapper script is not failing with an error anymore what is great.
However, it is still not working as the PATH contains invalid entries:

$ ide env --bash
export PATH="/d/projects/IDEasy/software/jmc;D:/projects/IDEasy/software/node;D:/projects/IDEasy/software/java/bin;D:/projects/IDEasy/software/mvn/bin;D:/projects/IDEasy/software/az/bin;D:/projects/IDEasy/software/intellij/bin;D:/projects/IDEasy/software/sonar/bin;D:/projects/IDEasy/software/aws;D:/projects/IDEasy/software/eclipse;C:/Users/hohwille/bin;C:/Program Files/Git/usr/local/bin;C:/Program Files/Git/usr/bin;C:/Program Files/Git/usr/bin;C:/Program Files/Git/opt/bin;D:/oracle-xe/product/18.0.0/dbhomeXE/bin;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/WINDOWS/System32/WindowsPowerShell/v1.0;C:/WINDOWS/System32/OpenSSH;C:/Program Files (x86)/GnuPG/bin;C:/Program Files/SlikSvn/bin;C:/Program Files/TortoiseSVN/bin;C:/Program Files/Git/cmd;C:/Program Files/Rancher Desktop/resources/resources/win32/bin;C:/Program Files/Rancher Desktop/resources/resources/linux/bin;C:/Users/hohwille/scripts;C:/Program Files/Git/usr/bin/vendor_perl;C:/Program Files/Git/usr/bin/core_perl"

There are various C:/Program Files entries. When we call this with --bash then all paths need to be printed in bash syntax.
This currently has very bad effects:

$ ls ../../software/
bash: ls: command not found

@hohwille hohwille reopened this Mar 21, 2024
@github-project-automation github-project-automation bot moved this from ✅ Done to 📋 Backlog in IDEasy board Mar 21, 2024
hohwille added a commit to hohwille/IDEasy that referenced this issue Mar 21, 2024
hohwille added a commit that referenced this issue Mar 21, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in IDEasy board Mar 21, 2024
@hohwille hohwille added this to the release:2024.03.001 milestone Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bash bug Something isn't working windows specific for Microsoft Windows OS
Projects
Status: ✅ Done
3 participants