0

I have created a simple shell script which executes another shell script within the same directory. Both scripts work without issue when executed outside of cygwin, but when I execute the file in mintty, I get a "No such file or directory" error.

I have tried altering the line in the script executed first to access the second script in several ways such as . ./script2.sh and ./script2.sh with the same results.

NOTE 1: I realize there are several similar questions, however none seem to exemplify or resolve the exact issue that I am having, at least not that I was able to find.

NOTE 2: Since these scripts are going to be distributed and shared amongst several users, I would like to resolve this issue without having to make any manual changes to my PATH settings.

The contents of my main script (called mainScript.sh) in the original form (without any of my attempted changes) are as follows:

    #!/bin/bash

    . script2.sh

The full command I use from Windows command prompt is: c:\path\to\mintty.exe -h always -e /cygdrive/C/Users/path/to/script/mainScript.sh

I receive this error message upon execution: /cygdrive/C/Users/path/to/script/mainScript.sh: line 3: script2.sh: No such file or directory

Blake Simmons
  • 426
  • 1
  • 8
  • 23
  • 2
    When you don't specify the path to the second script, the shell searches for it in the current $PATH. If you don't want to change $PATH, specify the full path to `script2.sh`. – choroba Jul 29 '19 at 19:04
  • Would this not be accomplished using the relative path, `./script2.sh` which I tried? Or am I missing something – Blake Simmons Jul 29 '19 at 19:04
  • 2
    Relative path is means relative to from where you run the script, not where it's located. – choroba Jul 29 '19 at 19:20
  • I see. So it's looking for script2.sh from whatever directory I'm in when I enter the full command? In this case C:\Users? – Blake Simmons Jul 29 '19 at 19:25
  • 3
    @BlakeSimmons Yes. Referring to files relative to the script's location is actually difficult (and sometimes impossible/meaningless). See [BashFAQ #28](http://mywiki.wooledge.org/BashFAQ/028). – Gordon Davisson Jul 29 '19 at 19:25
  • Understood. Thank you. – Blake Simmons Jul 29 '19 at 19:37

1 Answers1

1

I believe you will be enlightened by adding a pwd, echo $PATH and a ps after the first line of your script. Compare those results to what you see when you start an interactive session with mintty and issue the same commands.

Doug Henderson
  • 785
  • 8
  • 17