Subject: Re: Running a command in a specific directory
From: Brian Inglis <[email-masked]>
To: [email-masked]
Date: Wed, 23 Mar 2022 01:21:27 -0600
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>

On 2022-03-22 16:35, Piotr Gliźniewicz wrote:
> I'm trying to run a command at a specific "Windows" path. Basically 
> something similar to what chere does for bash, but I want to execute ls 
> in bash for a specific directory. I've tried variations of what chere 
> leaves in the registry:
> C:\cygwin64\bin\bash.exe -c "/bin/xhere /bin/bash.exe '%L'"
> Adding simply `-c ls` didn't work.
> To start with something simpler I've launched bash and tried just to 
> guess what xhere want's, but I don't really know what's happening. I 
> couldn't find any help for xhere.
> /cygdrive/c
> $ /bin/xhere '/bin/bash.exe -c ls' d:
> /bin/xhere: line 38: [: too many arguments
> /bin/xhere: line 41: [: too many arguments
> /bin/xhere: line 64: [: too many arguments
> Starting /bin/bash.exe -c ls
> -/bin/bash: ls: command not found
> /cygdrive/c
> $ /bin/xhere "/bin/bash.exe -c ls" d:
> /bin/xhere: line 38: [: too many arguments
> /bin/xhere: line 41: [: too many arguments
> /bin/xhere: line 64: [: too many arguments
> Starting /bin/bash.exe -c ls
> -/bin/bash: ls: command not found
> Any hints, how to properly pass `/bin/bash.exe -c ls` to xhere?

$ file `which xhere`
/usr/bin/xhere: Bourne-Again shell script, ASCII text executable
$ head `which xhere`
#!/bin/bash
# Have to use bash; can't get ash to "exec -l"
# Separate script from chere to avoid need for argument parsing
#
# first arg is shell
# second arg is the path
...

Can't do that: xhere expects shell path /bin/*sh* and directory path and 
runs under bash so it can run exec -l to exec shell as login shell after 
cd dir.

Starting XWin Server from a shortcut uses:

C:\...\cygwin...\bin\run.exe --quote /bin/bash -l -c "cd; exec 
/bin/startxwin"

so you could base a commnad line on that.

You could also install and use Cygwin-X with a GUI file manager like 
PcManFM, or a text version like Midnight Commander (package mc).

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple