How to process json in bash script in windows environment - windows

I am writing bash script that is supposed to work both on linux and windows environment. To enable bash on windows we have installed cygwin.
Seems jq lib can handle json but not sure will it work on windows environment too?
Same with sed not sure how to enable it in windows environment?
Some other libraries?

I have jq installed on cygwin and it can handle json data in Windows.
You can install jq on Cygwin by two ways
1) Run this in cmd. setup-x86_64.exe is your cygwin installation binary
setup-x86_64.exe -q -P jq
2) Install apt-cyg(the package manager of cygwin similar to yum) and run on cygwin
apt-cyg install jq
NOTE: The details of installing packages on Cygwin is mentioned How do I install cygwin components from the command line?

Related

"conda: command not found", Bash on Windows

I have installed Bash for windows by activating the Windows Subsystem for Linux and installing Ubuntu and when I installed Anaconda I selected the "Add Anaconda to my PATH environment variable" setting, so I do not believe there are any issues with PATH.
What I see in my Edit environment variables window is:
C:\Users\user\anaconda3
C:\Users\user\anaconda3\Library\mingw-w64\bin
C:\Users\user\anaconda3\Library\usr\bin
C:\Users\user\anaconda3\Library\bin
C:\Users\user\anaconda3\Scripts\
In Bash, when I enter something such as conda info --base I get conda: command not found
However, when I run the same command in Git Bash, it runs just fine.
From within git bash, you can type, command -v conda, as it will output the location to the executable. Add the directory to your PATH environment variable.
Eg from within git bash:
$ command -v my_command
/c/path/to/bin/my_command
Then prefix the value with /mnt and add it all: /mnt/c/path/to/bin to your PATH environment variable. And reopen your bash shell.
you can:
use git-bash / PowerShell / CMD for Anaconda
use Windows Terminal for easily using multiple shells
modify ~/.profile to include the Anaconda folders to PATH. /mnt/c/Users/user/Anaconda3...
NB you may experience issues with file paths or output
in advance, you could check the output of echo "${PATH//:/$'\n'}" | grep -i conda in a new session of bash
because typically, Windows and WSL should have already configured this for you
install Anaconda on WSL following official Linux instructions for your distro
if unsure which distro, it's likely Ubuntu. so instructions for Debian, the parent of Ubuntu
WSL is a complete Linux virtual machine and not your best bet for running (cli) software that you installed on Windows. you can but i would personally prefer installing the Linux version in WSL.

How to use scp command in conda

I'm trying to upload some files onto a remote server but the command scp is not installed on my laptop. I'm working with Anaconda on a Windows 10 machine and the server is a Linux machine with Ubuntu 18.04.
To my intuition, I think it's easier to install scp directly with conda than to install it on Windows (I'm actually using Anaconda Prompt rather than Windows DOS), so following the instruction of Anaconda website I ran
conda install -c remram scp
after which I reran the scp command, only to find scp still not installed.
I have double-checked other dependent tools like ssh and also updated my conda, but nothing worked.
Is it even possible to use scp on a conda environment when there isn't an scp on my computer? If so, what's the correct thing to do to make it available? If not, can anyone share a reliable way to install scp on Windows system?

How do I install md5deep in Git Bash (Windows 7)

How do I install md5deep in Git Bash as the make command is not working in Git Bash.
I tried with wget, apt-get and a few other methods.
Git Bash does not ship with GNU Make or package utilities. For that you would need Cygwin.
If you would like a more "official" means, try Bash on Ubuntu for Windows which I find more streamlined and easier to use.
If you'd like the latter, Windows 10 is still free for Windows 7 users.

How to install sshpass on Windows through Cygwin?

In the packages window of CygWin, when I type sshpass, nothing comes up. I tried installing similar packages like openssh etc hoping one of them contains sshpass but no luck.
sshpass is not available as Cygwin package. This means that you need to build and install from source. To build sshpass on Windows (Cygwin):
$ curl -LO http://downloads.sourceforge.net/sshpass/sshpass-1.06.tar.gz
$ md5sum sshpass-1.06.tar.gz
f59695e3b9761fb51be7d795819421f9
Build and install to /usr/local/bin:
$ tar xvf sshpass-1.06.tar.gz
$ cd sshpass-1.06
$ ./configure
$ make
$ sudo make install
Which installs two files
the executable /usr/local/bin/sshpass
man page /usr/local/share/man/man1/sshpass.1
Your Cygwin install needs to have the required tools: curl to download, tar to extract, and autoconf, make and gcc to build. I'll assume reader familiarity with installing packages on Cygwin.
sshpass is not available as cygwin package. This means that you need to build and install from source.
See for reference on existing alternative
https://www.cygwin.com/ml/cygwin/2015-02/msg00042.html
This does not directly answer the question "How to install sshpass on Windows?", but can be much easier solution if you need to automatically enter the password when ssh-ing to a machine on Windows system, you can use Plink (part of PuTTY).
plink your_username#yourhost -pw your_password
Window 10 comes with Linux subsystem, you can install a favor of Linux through Windows Store. Then all Linux commands comes easily. sshpass can be easily installed in the subsystem. WSL(Windwos Subsystem for Linux) is the future.

Can openssh be installed on MSYS?

I'm using MSYS in windows 7 and now i need it to provide ssh server service. can openssh be installed in msys like it is in cygwin?
i can find ssh in /msys/bin, and it can be used as ssh client. but no server seems to be installed. how can i install one? i googled a lot but almost every theads leads to openssh in cygwin, that does not apply to my situation.
i compared cygwin and msys and decide to use msys. We need to run some applications both built and supposed to be ran in windows.
what i've tried:
mingw-get install mysys-openssh
test#WIN-L3L622JBT6G ~
$ mingw-get install msys-openssh
install: openssh-5.4p1-1-msys-1.0.13-bin.tar.lzm
installing openssh-5.4p1-1-msys-1.0.13-bin.tar.
install: openssh-5.4p1-1-msys-1.0.13-doc.tar.lzm
installing openssh-5.4p1-1-msys-1.0.13-doc.tar.
install: openssh-5.4p1-1-msys-1.0.13-lic.tar.lzm
installing openssh-5.4p1-1-msys-1.0.13-lic.tar.
test#WIN-L3L622JBT6G ~
$ openssh
sh: openssh: command not found
the package seems to be installed but i don't know how to find the service. do i need to link it or modify the profile?
The answer would be "NO".
Msys provide ssh client but not ssh server, as it's document indicates.
And Openssh cannot be installed on windows without cygwin. you can install a full cygwin and install openssh in cygwin. It's also feasible to only install partial cygwin.
Msys is outdated. Use Msys2, which does support sshd: https://www.booleanworld.com/get-unix-linux-environment-windows-msys2/

Resources