0

I have some bash scripts that I wanted to use like batch files in windows 10 by double clicking and let it to finish the job. Problem is it starts the script from windows system (C:\Windows\System32) directory (I chose bash C:\cygwin\bin\bash.exe to run .sh scripts but they didn't work. After a while I have added read xyz at the end to keep the script alive and checked in process explorer that it starts from windows system directory. This way script trying to create archive in there gets denied access).

Neither bash nor script is in that directory. In XP it used to work fine. In supposedly "modern" 10 it does not. How to change that so it starts in current/script directory?

[ed] The script can be as simple as and is located in c:\tmp:

#!/bin/sh
rar a bak.rar *.txt

After adding some debugging code:

#!/bin/sh
pwd
rar4 a bak.rar *.txt
read xyz
/cygdrive/c/WINDOWS/system32
(...)
Cannot create bak.rar
Access is denied.

pwd evidently shows it's run from windows\system32 directory, which is the whole mystery.

6
  • Do you have a file with the same name in your folder and in System32? Is your current directory when in bash is System32? What is your PATH?
    – harrymc
    Commented Jul 12, 2022 at 20:05
  • No, script is called nothing like anything in windows directory. I am not in bash console and my current directory is where the script lies. All I do is to double click on script which brings me to the window where I choose bash, which is in C:\cygwin\bin\bash.exe. An yes, There is a PATH to C:\cygwin\bin.
    – tansy
    Commented Jul 12, 2022 at 20:30
  • 1
    System32 is the default working directory fo apps launched as admin. I myself would use WSH and not CYGWIN for this but you do you. I believe that you can launch the bash console directly to run your script and set the working directory all via one simple LNK (shortcut) file. Commented Jul 12, 2022 at 20:47
  • I'm not administrator as a user. Making shortcuts to scripts is not an option. It's just another script to script. Batch files work as expected.
    – tansy
    Commented Jul 12, 2022 at 20:58
  • @señor-cmasmas: that remark about working directory helped me to solve the question. Thanks anyway.
    – tansy
    Commented Jul 14, 2022 at 21:26

1 Answer 1

0

I solved it by fully associating .sh files with bash. Now it works as other scripts (batch for example). It very well may be because default working directory for apps launched as @señor-cmasmas said, not only admin but system in general and window to choose which program is actually a program "C:\Windows\System32\OpenWith.exe".

You must log in to answer this question.

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