Run sha256sum (from Cygwin) on file with special character and blank (quoting does not work) - powershell

I have Cygwin installed in order to use Linux command line tools on Windows. I also added it to my PATH. In general, it works fine, but I observe this weird behavior:
I want to run sha256sum on the file C:\Users\s1504gl\Desktop\Täst .txt. Note the german Umlaut ä and the whitespace before the file extension. In order to avoid problems with paths, I always quote paths in command line calls, such as:
sha256sum "C:\Users\s1504gl\Desktop\Täst .txt"
However, PowerShell returns
/usr/bin/sha256sum: '"C:\Users\s1504gl\Desktop\T'$'\303\244''st .txt"': No such file or directory
When I rename the file to either Täst.txt or Test .txt, it works. So the combination of the special character ä and the whitespace seems to cause the problem. Exchanging double quotes by single quotes does not change anything in this case.
I am pretty sure it has to to with PowerShell since the example works without any problems on my Linux machine.
Is there some other way of escaping special characters and/or blanks that I do not know?

Run from Cygwin terminal
sha256sum "/cygdrive/C/Users/s1504gl/Desktop/Täst\ .txt"
In general Cygwin program do not accept Windows paths and works surely with POSIX path

I found the following workaround:
I create a temporary file from R, containing all the necessary commands and then run this tempfile using bash which is also included in Cygwin. This way, I escape from the problem occurring due to different encodings in Windows and the Linux tools from Cygwin.

Related

How can I avoid that echo in Windows PowerShell creates binary files?

I am a long-time Linux user and am used to a command like:
echo 'hello' > a.txt
creating a plaintext file simply containing 'hello'.
Now, if I use the same command in Windows PowerShell, the resulting file is claimed to be binary (by git). If I inspect the file in a text editor, the file contains the text but some weird excessive characters that look like a character encoding issue.
How am I supposed to use echo instead to make it behave in a completely "ordinary" plaintext way?

perl glob matching files on windows vs linux

I have the following code in a cgi script that just bundles up xml files into a zip for downloading:
my $obj = Archive::Zip->new();
foreach my $xml_file (glob(File::Spec->catfile($in_path,"*.xml")))
{
$obj->addFile($xml_file);
}
$obj->writeToFileNamed($zipfile_name);
This works fine on unit tests and when I run it on Linux, but when installed on windows, I get:
Can't call method "desiredCompressionLevel" on an undefined value at /usr/share/perl5/Archive/Zip/Archive.pm line 249.
In both cases, it works fine on Linux and under unit test, but fails when installed on windows (there are xml files in the directory that should be picked up...).
I think choroba's comment is correct. Since it only happens when you install on windows rather than when you test on windows, I'll bet that it is a "C:\Program Files" space issue. It is listed in the docs for perl's File::Glob:
Due to historical reasons, CORE::glob() will also split its
argument on whitespace, treating it as multiple patterns, whereas
bsd_glob() considers them as one pattern.
This could easily break things. The docs recommend using bsd_glob() instead of glob in this case.
I can cut and paste your code and run it on windows with $in_path == ".", but it breaks when I use $in_path = "C:\Path With Spaces". Also, with spaces, I am pretty sure it will fail on linux as well.

how to make cygwin tar output proper unicode letters instead of shashed values?

I have a *.tar.gz file that have inside occasionally some names with non ascii letters.
for example when tar encounter a file containing word: naïve it outputs: na\303\257ve
Is there any swich, or tool to convert these slashed values to a proper letter ?
http://www.gnu.org/software/tar/manual/tar.html
By default GNU tar attempts to unquote each file or member name, replacing escape sequences according to the following table: ...
This default behavior is controlled by the following command line
option:
--unquote
Enable unquoting input file or member names (default).
--no-unquote
Disable unquoting input file or member names.
In other words, see if "--no-unquote" is an option for your version of Cygwin.
PS:
Which version of Cygwin tar are you using?

Git push corrupting my export with '\r' characters

Whenever i push through git all my bash scripts seem to be corrupted with the \r character. It doesn't affect the code, but it just adds a significant amount of noise to my work. Looked all over the web, but can't seem to find a solution.
Example:
echo "*************************************************************************"\r
^
Every line in my bash scripts are always ended with this special character. I use STS on Windows 7. Any ideas?
Put this two lines into your .gitconfig file in the root of your repo or into your home if you need to make this settings global :
[core]
eol = lf
You can find more about this here : https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

Running a perl script in a batch file

i have a perl script that is used in updating my awstats logs of my website. The script works fine if i just paste it in cmd (Windows) but the moment i paste it in a batch file, it messes up the format of the files generated (they should be prepended with current date/time). The code is:
perl C:\PROGRA~2\AWStats\tools\awstats_buildstaticpages.pl -config=mywebsite -update -awstatsprog=C:\PROGRA~2\AWStats\wwwroot\cgi-bin\awstats.pl -dir=C:\myfolder\stats\reports -builddate=%YYYY%MM -buildpdf=C:\PROGRA~2\HTMLDOC\ghtmldoc.exe -staticlinksext=asp`
The resulting files generated is mysite.201008.asp if i paste it in cmd and execute BUT In a batch file with the same script, my resulting file is mysite.MM.asp.
Any idea why this is happening?
The problem is caused by %YYYY%MM.
"%" is a special symbol in batch files. You need to escape it by doubling it: %%YYYY%%MM.
It appears you have to escape the '%' characters.
The command shell doing variable substitution on %YYYY% which I'm guessing is not defined in your environment, so it substitutes the empty string for that "variable".
Unfortunately, there are no opaque quotes in the Windows shell.