Powershell,pash Trial notes under Linux

Source: Internet
Author: User

------1 Overview------

1.1 In simple terms Linux,unix is very dependent on scripting, and win is not. Win has a lot of graphics program +c Library, the efficiency is not worse than the script. A few mouse clicks can still complete the requirements. Of course, graphics and characters are different and cannot be completely replaced.

1.2 Win's bat and bash in Linux are old scripting languages that have been on the battlefield for decades and have been meritorious. But because it is too old, there are many limitations and flaws. It's a lot worse than Python and PowerShell. In general, it's not fun to play Python and PowerShell. In short, the new is a big alternative to the old trend.

1.3 In short, pash is bash+ third-party PowerShell.

1.4 Pash than bash (main)?

1.4.1 I think Pash inherits the simple syntax of PowerShell, which conforms to the virtues of habit. If you use curly braces to make code snippets, there are foreach, and so on.

1.4.2 Pash calls the Mono library, which is an object-oriented script. Supports static, dynamic. NET classes. such as: "ABc". ToUpper ()

Of course, the support of the class library is not perfect, you need to contribute code.

1.5 to C # program ape:

Although PowerShell calls. NET syntax simpler than C #, many C # people do not want to use PowerShell syntax. They want to use C # syntax to do the shell, because they are familiar with C #, they should see the shell syntax is the same as C #.

But they still go around the "object-oriented command-line class library." The "Object-oriented command-line class library" is mostly in System.Management, and the "Pipeline of Supported Objects" feature, which was invented from PowerShell.

The PowerShell missionary original article began with 2014-09-20,2014-11-30,2015-01-18,2015-03-11 modification. Article version of the current blog park for the latest version. Permission to reprint, but must retain the name and provenance, otherwise investigate legal liability

------2 Pash is now implemented with the following command:------
add-Memberadd-Pssnapinadd-Type Clear-Variable Convert-Path ConvertTo-CSV ConvertTo-Html Copy-Item Export-CSVForEach-Object Format-DefaultFormat-List Format-Table Get-ChildItem Get-Command Get-Date Get-Help Get-History Get-Host Get-Location Get-Member Get-ProcessGet-psdrive Get-Psprovider Get-PSSnapin Get-Random Get-Service Get-Variable Import-CSV Join-Path Move-Item New-Alias New-Item New-Object New-Variable out-Default out-file out-Null Remove-Item Remove-PSSnapin Remove-Variable Rename-Item Restart-Serviceresume-Service Select-Object Set-Alias Set-Location Set-Variable Sort-Object Split-Path Start-Service Start-Sleep Stop-ProcessStop-Service Suspend-Service Tee-Object Write-Debug Write-Error Write-Host Write-Output Write-Progress Write-Verbose Write-warning
View Code

Features of PowerShell command: Select-object,where-object,group-object, only the first one is implemented.

There are no invoke-* commands. such as: Invoke-command. There are get-variable commands, but the following is not the same as the variable name.

Import-module This heavyweight command is not yet supported.

------3 Test the contents of the script------

Slightly

------4 Pash Trial Conclusion------

Only test the UTF8 encoding to save the file.

4.1 Benefits:

4.1.1 Carriage return is set to Cr,lf,crlf to run correctly.

4.1.2 spaces are set to spaces, tab, and full-width spaces to work correctly. ----Bash does not recognize Chinese spaces, which are full-width spaces, but pash does not have this problem.

4.1.3 supports Chinese function name, Chinese variable name. -----Good

4.1.4 supports static classes, static methods, and this notation, such as: [Array]::sort ($MMM)

The 4.1.5 command is case-insensitive, get-process and get-process are useful.

4.1.6 Chinese support is better than native PowerShell, see the test code for Mahjong 80,000.

The 4.1.7 supports variable scopes and works fine.

4.1.8 supports-match and results are correct.

The 4.1.9 supports-F and the results are correct.

4.1.10 support $a++, $a-et.

The latest version of 4.1.11 has fixed the following issue.

Undefined reference variables are not supported, such as: $temp 2 = $temp 2 + ' AAA ' but supported: $temp 2 = ' aaa ' + $temp 2

4.1.12 The latest version has support for do {} while (), and while () {}.

4.2 Currently does not support:

4.2.2 does not support switch. ----This problem is not big, I prefer if nested, more intuitive.

4.2.3 Array: Contains parameters not supported, that is,-contains, and $ array are not supported. Contains ("a"). Arrays also do not support-join.

String:-replace is not supported.

What are these? It's just a grammar candy.

What is the grammatical sugar?   is for the novice programmer made, simple and easy to use features. Without these functions, we can still use the native one. NET syntax instead.

such as String.Replace:

$aaaa = ' aaaa?cccc?ddd? kkkkk '    $bbbb $aaaa. Replace ('? ', '-')   write$bbbb

4.2.4 does not support a reference at @ ' @,@ ' @. I have brought the carriage return before and after the----and tested it in win.

4.2.5 does not support variable prefix [string] $a, [int32] $a.

4.3bug:

4.3.1 Else,elseif cannot be placed at the beginning of the line. -----This bug has been fixed

---------------5 Pash Reviews-----------------

Get-content not support is really bad. But then, do we waste all our kung fu?

Fortunately, creating alias New-alias and $profile functions is good, so we can create aliases using native Linux commands.

such as: echo "New-alias get-content-linux/usr/bin/cat" >>/root/. Pash_profile.ps1 #这里的root根据用户名改变.

So we have get-content-linux this command, and our martial arts are all back.

---------------6 pash Script case-----------------

#!/opt/mono/bin/mono/pash/source/pashconsole/bin/debug/pash.exe#Test2.ps1#Insert ' AAA ' before each line of text$ to process the file= '/etc/sysconfig/network-scripts/ifcfg-Lo '$ per line of file= Get-content-linux$ to process the fileforeach($temp  inch $ per line of file) {      $temp 2=$temp 2+ ' AAA ' +$temp+"' r ' n"} out-file $temp 2/root/ttt.txt-encoding UTF8

---------------7 Pash Installation-----------------

7.1 Installing Mono

7.2 git and compile pash

Specifically look at a post http://www.cnblogs.com/piapia/p/4279253.html

---------------8 thousand words summed up into one sentence:-----------------------

Hope that we study more, more attention to PowerShell, more attention to pash, more share ~ ~ 2015-01-18

Powershell,pash Trial notes under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.