0

I am using Cygwin on Windows 10 and ran the below commands so I could Double Click and execute bash/shell scripts in file explorer without happening to run them by opening Cygwin itself:

assoc .sh=bashscript
ftype bashscript=C:\cygwin64\bin\bash.exe --login -i -c 'cd "$(dirname "$(cygpath -u "%1")")"; bash "$(cygpath -u "%1")"'

The issue I am having is whatever command I run which creates a folder or file, it adds a weird · symbol to the end of files.

For example, if I have a bash script that simply has the command:

mkdir bob

It will create a directory called: bob ·

Any ideas as to how or why this is happening? If I run these commands manually in the Cygwin terminal everything works fine.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Bob
  • 33
  • 7
  • 1
    After running `mkdir bob` and getting that directory created, run `set -- bob*; printf '%q\n' "$@"` manually in a terminal, and give us the results here -- that'll give an unambiguous representation of what that symbol actually *is*. – Charles Duffy Mar 14 '17 at 14:47
  • 1
    ...that said, `%1` isn't actually meaningful in bash (it's a Windowsism). If you want to refer to the bash script's parameters, you'd want `"$1"`, which will refer to the first argument *after* the script passed following `-c`. – Charles Duffy Mar 14 '17 at 14:48
  • By the way, it's... very unusual... to use `-c` with `-l` and `-i`, and I'm not sure it serves a purpose here. Are you sure you don't want to pass those latter arguments only to the second, inner `bash` instance, not the initial outer one? Though when you're giving them a script to execute, they're probably not appropriate there either. (A shell executing a script is by definition not *interactive*). – Charles Duffy Mar 14 '17 at 14:50
  • My first guess, without actually testing this on Windows, would be that you might want something more like `ftype bashscript=C:\cygwin64\bin\bash.exe -c 'scriptname=$1; shift; cd "$(dirname "$(cygpath -u "$scriptname")")" && exec bash "$(cygpath -u "$scriptname")" "$@"' %1 %2 %3 %4 %5 %6 %7 %8 %9`. But I don't know quoting/expansion rules on Windows, so there's no guarantee that that's right. – Charles Duffy Mar 14 '17 at 14:52
  • 1
    I ran the command from your first comment and it returned: $'bob\r' – Bob Mar 14 '17 at 15:05
  • Ahh! So your character is a CR -- the extra character found in a DOS newline but not a Windows one. – Charles Duffy Mar 14 '17 at 15:06
  • Silly question -- is the script you're running in DOS or UNIX format? If it has literal CRLFs for its endlines, well, there's your problem, and it has nothing to do with the `ftype` definition. – Charles Duffy Mar 14 '17 at 15:07
  • I think the file in using Dos\Windows format? – Bob Mar 14 '17 at 15:12
  • Well, that's your problem. Re-save it as a UNIX file -- if your editor is vim, you can run `:set fileformat=unix` – Charles Duffy Mar 14 '17 at 15:13
  • 1
    I was using Notepad++ but I saved as UNIX and it worked! Awesome man, thank you very much for the help. Lesson learnt. :) – Bob Mar 14 '17 at 15:17

0 Answers0