简体   繁体   中英

Cygwin gives “No such file or directory” error when running a shell script that executes another shell script

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 . ./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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM