1

I'm trying to get PETSc running under Cygwin on my Windows machine to test parallel code. Unfortunately there's a problem where Cygwin is importing elements from my Windows path of the form:

C:\Program Files (x86)\...

And the problem is that the PETSc and MPI compilers are falling on their faces because they don't invoke cygpath to fix the " " characters. So, I need help with one of three things:

  1. How to get Cygwin to not load the Windows path

    • I put it on its own partition and am trying to use only native Cygwin compilers so it could, hopefully, live without knowing much about Windows.
  2. Rewrite my PATH variable to escape all the " " characters by replacing them with "\ "

I know this:

       echo $PATH | sed 's/ /\\ /g'

Does exactly what I need, but I can't get it to execute as an "export PATH=" command in .bashrc. I've tried:

export PATH='echo $PATH | sed '"'"'s/ /\\ /g'"'"' '

Which just breaks my Cygwin session to the point that I need to repair .bashrc in Notepad++ to boot again

export PATH="echo $PATH | sed 's/ /\\ /g'"

Which just prepends "echo " and appends " | sed 's/\ /g" to PATH.

export PATH='echo $PATH | sed "s/ /\\ /g"'

Which replaces my entire path with just "echo $PATH | sed "/\ /g"

  1. Something I haven't thought of at all.

Any help would be greatly appreciated.

2
  • you can redefine PATH on you startup scripts. Usually that is already available , which shell are you using ?
    – matzeri
    Sep 14, 2016 at 6:19
  • To set a variable to output from a command, called 'command substitution', use backquotes (which I can't easily show because stack markdown uses them, but on US keyboard the key at the top left not the one next to Enter) or usually better dollar-parentheses PATH=$( echo $PATH | sed ... ). But you don't need to run any command for this, bash can do it: PATH=${PATH// /\\ } And personally when I have a choice I just use the shortname e.g. C:\Progra~2\Whatever and avoid the problem. Sep 14, 2016 at 6:49

1 Answer 1

0

How to get Cygwin to not load the Windows path

For the bash shell this can be done by making some small changes to ~/.bash_profile.

I like to have complete control over the PATH in Cygwin bash, so I added the following code to my ~/.bash_profile

# Build up the path using the directories in ~/.path_elements
unset PATH
while read line; do 
  PATH="${PATH}$line"; 
done < ~/.path_elements

# Add current directory to path
export PATH=".:${PATH}"

Notes:

  • unset PATH removes any PATH already configured by the Cygwin startup code.

  • The while loop reads in path elements from a file in my home directory (~/.path_elements) to build up my preferred PATH

  • Finally we add the current directory . to the PATH and export it.

  • Adding the current directory to the PATH could be considered as a security risk since built in commands could be replaced by commands located in the current directory. Please bear that in mind if you choose to use my code.

The contents of my ~/.path_elements are as follows. Modify and season to your taste to add extra elements to the path.

/home/DavidPostill/bin:
/usr/local/bin:
/usr/bin:
/c/Windows/system32:
/c/Windows

Result:

DavidPostill@Hal /f/test
$ echo $PATH
.:/home/DavidPostill/bin:/usr/local/bin:/usr/bin:/c/Windows/system32:/c/Windows
5
  • As PETSC is like connected to other math library, "usr/lib/lapack" could also be need for Lapack
    – matzeri
    Sep 14, 2016 at 12:16
  • @matzeri Libraries are not normally added to PATH...
    – DavidPostill
    Sep 14, 2016 at 12:18
  • shared lib yes. It is the reason why major cyg*dll's are in "/usr/bin" and not in "/usr/lib". Lapack as package has an exception to avoid collision with other optimized BLAS. cygwin.com/packages/x86_64/liblapack0/liblapack0-3.6.1-1 It was like that from the origin: cygwin.com/ml/cygwin-apps/2005-06/msg00198.html
    – matzeri
    Sep 14, 2016 at 12:28
  • @matzeri Fair enough. I did say "Modify and season to your taste to add extra elements to the path." in the answer ;p
    – DavidPostill
    Sep 14, 2016 at 12:29
  • @DavidPostill Works like a dream. The installer for PETSc still doesn't behave super well under Cygwin so I had to add the petsc/.../lib and petsc/.../bin directories to PATH as well.
    – Thulkos
    Sep 15, 2016 at 0:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .