Search code examples
c++powershellintellij-ideaideclion

Test a shell (.sh) file in CLion


I am using Clion and I am unsure how to run a .sh file with my code. It is for an assignment, and I have to run an automatic test to test my code.

This is how it is described to be called: $ ./test_p2.sh 2

I have the shell file in the folder with my code, But I cannot see it in executable or working directory.

Any help is appreciated! Thanks


Solution

  • You can't directly run Linux shell scripts on Windows. You do have a few options, however:

    1. Run your script through Cygwin
    2. Run your script in mintty (this is the shell included with Git for Windows, is called Git Bash in the context menu)
    3. Run your script under WSL (Windows Subsystem for Linux)
    4. Port the script to another language you can run on Windows

    For 1 and 2, it'll be on you to make sure any dependencies for the script are available in either Cygwin or mintty.

    For 3, after making sure WSL is set up you can run a single command under WSL: wsl script.sh arg1 arg2 argX.

    I would recommend option 3 or 4. 3 may offer the best experience in terms of compatibility and ease of set up (without porting the script) as Cygwin and mintty can be a pain to set up dependencies in. Option 4 would be best though as long as you are well-versed in both PowerShell and shell scripts and can transpose the equivalent calls from one to the other.