Use Cygwin command from powershell

Susja 751 Reputation points
2022-09-11T11:41:45.083+00:00

Hello
I widely use Unix/Posix like commands in my daily activities.
I have only Windows environments.
For that reason I use utility called MobaXterm which is built on top of Cygwin and allow me to use utilities like awk, sed, Grep and etc.
I noticed that Power shell on my PC works significantly faster than MobaXterm hence I want to use it from inside the powershell.
E.g. instead of using poweshell ‘Select-String’ I want to use Cygwin’grep’
How should I do it? Could I change the path to MobaXterm bin directory to make powershell aware of it? Or something similar?
Note: I do not have admin privilege on my PC
Appreciate your help

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2022-09-11T15:05:18.023+00:00

    PowerShell, like bash, Bourne, Csh, is just a shell. MobaXterm provides a X-Server (a graphical wrapper) in which you can run a shell. But all the utilities in a classical Unix/Linux server would only need a basic shell to work because they work with text files and need a TTY interface to work. MobaXterm is more for your convenience than a requirement to use CygWin.

    You just have to tell whatever shell you use where your stuff lives: Try this how-to-run-cygwin-script-in-powershell

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2022-09-11T14:08:33.203+00:00

    If you only have Windows environments, then why don't you just use native Powershell commands? If you don't have admin access, then you will have trouble getting 3rd party Unix command emulators installed on all of the machines that you need to support.

    Yes, you will have a learning curve but they should run faster and you can take advantage of all of the Powershell cmdlets. Powershell has aliases so you will find that commands like "ls" work.

    PS C:\> get-alias  
      
    CommandType     Name  
    -----------     ----  
    Alias           % -> ForEach-Object  
    Alias           ? -> Where-Object  
    Alias           ac -> Add-Content  
    Alias           cat -> Get-Content  
    Alias           cd -> Set-Location  
    Alias           chdir -> Set-Location  
    Alias           clc -> Clear-Content  
    Alias           clear -> Clear-Host  
    Alias           cls -> Clear-Host  
    Alias           compare -> Compare-Object  
    Alias           copy -> Copy-Item  
    Alias           cp -> Copy-Item  
    Alias           cpi -> Copy-Item  
    Alias           cpp -> Copy-ItemProperty  
    Alias           curl -> Invoke-WebRequest  
    Alias           del -> Remove-Item  
    Alias           diff -> Compare-Object  
    Alias           dir -> Get-ChildItem  
    Alias           echo -> Write-Output  
    Alias           erase -> Remove-Item  
    Alias           kill -> Stop-Process  
    Alias           lp -> Out-Printer  
    Alias           ls -> Get-ChildItem  
    Alias           man -> help  
    Alias           md -> mkdir  
    

    https://mathieubuisson.github.io/powershell-linux-bash/

    You can also run PS script's that emulate Unix commands like grep here.

    https://github.com/jagilber/powershellScripts/blob/master/grep.ps1

    Here is a good reference document.

    https://www.sapien.com/books_training/Windows-PowerShell-4

    1 person found this answer helpful.

  2. Susja 751 Reputation points
    2022-09-14T01:23:43.443+00:00

    Well I think I figured it out.
    It looks to me that my organization forces users to run Powershell from another location. When I created powershell profile in that location ... next time I started the shell it took effect but prevented to run due to the policy.
    I think that now it's clear why my change before did not take effect.
    Thanks for your help


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.