Linux powershell, pash trial note, powershellpash
------ 1 Overview ------
1.1 in linux, unix is very dependent on scripts, but win is not. Win has many graphics programs + c libraries, and the efficiency is no worse than that of scripts. Just a few clicks to complete the requirement. However, graphics and characters are two different things and cannot be completely replaced.
Bat in 1.2 win and bash in linux are both old scripting languages, which have been widely used for decades. However, because it is too old, there are many restrictions and defects. It is much worse to use than python and powershell. Generally, it is not easy to use python or powershell. In short, there is a new trend to replace the old.
1.3 In simple terms, pash is bash + third-party powershell.
1.4 Where Is pash better than bash?
1.4.1 I think pash inherits the advantages of the simple Syntax of powershell and conforms to the habits. For example, you can use braces to make the beginning and end of a code segment, such as foreach.
1.4.2 pash calls the mono library and is an object-oriented script. Supports static and dynamic. net classes. For example, "aBc". toupper ()
Of course, the support for class libraries is not complete yet and you need to contribute code.
1.5 to c # programmers:
Although powershell calls. net syntax is simpler than c #, many c # users do not want to use powershell syntax. They want to use c # syntax to create another shell, because they are familiar with c #, and the shell syntax in their eyes should be the same as c.
But they still cannot bypass the [object-oriented command line class library. Most of the object-oriented command line class libraries are in System. Management, and the [Support for object pipelines] function was invented from powershell.
The original Article of the powershell missionary started with 2014-09-20,-11-30,2015-01-18,2015-03-11. The article version is the latest version. Reprinting is allowed, but the name and source must be retained; otherwise, legal liability will be held.
------ 2 pash is currently implemented. the following command: ------ Add-MemberAdd-PSSnapinAdd-Type Clear-Variable Convert-Path convertid-Csv convertize-Html Copy-Item Export-Csv ForEach-Object Format-Default Format-List Format-Table Get- childItem Get-Command Get-Date Get-Help Get-History Get-Host Get-Location Get-Member Get-Process Get-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-Process Stop-Service suspend-Service Tee-Object Write-Debug Write-Error Write-Host Write-Output Write-Progress Write-Verbose Write-WarningView Code
Powershell's special commands: Select-Object, Where-Object, and Group-Object only implement the first one.
There is no invoke-* command. For example, invoke-command. The Get-Variable command is available, but whether it is followed by the Variable name does not work.
The Import-Module heavyweight command is not supported yet.
------ 3 test script content ------
Omitted
------ 4 pash trial conclusion ------
Only UTF-8 encoded files are tested.
4.1 Benefits:
4.1.1 if you press enter to set cr, lf, or crlf to run correctly.
4.1.2 If spaces are set to spaces, tab keys, and full-width spaces, the system can run properly. ---- Bash cannot recognize Chinese spaces, that is, full-width spaces, but pash does not.
4.1.3 Chinese function names and Chinese variable names are supported. ----- Good
4.1.4 supports static classes, static methods, and such writing methods, such as [array]: Sort ($ mmm)
4.1.5 The command is case-insensitive. get-process and Get-Process are both easy to use.
4.1.6 Chinese support is better than native powershell. For more information, see the test code of mahjong 80 thousand.
4.1.7 supports variable scopes and works properly.
4.1.8 supports-match and the result is correct.
4.1.9 supports-f and the result is correct.
4.1.10 supports $ a ++, $ a --, and so on.
4.1.11 the latest version has fixed the following problem.
Variables referenced first are not defined, for example, $ temp2 = $ temp2 + 'aaa'. However, the following conditions are supported: $ temp2 = 'aaa' + $ temp2
4.1.12 the latest version supports do {} while (), and while (){}.
4.2 currently, this feature is not supported:
4.2.2 switch is not supported. ---- This problem is not big either. I prefer if nesting, which is more intuitive.
4.2.3 array: contains parameters, that is,-contains and $ array. contains ("a") are not supported "). Array does not support-join.
String:-replace is not supported.
What are these? It's just syntactic sugar.
What is syntactic sugar? It is a simple and easy-to-use function made for cainiao programmers. Without these features, we can still use native. . Net syntax.
For example, string. replace:
$aaaa = 'aaaa?cccc?ddd?kkkkk' $bbbb = $aaaa.replace('?','-') write-host $bbbb
4.2.4 reference of @ ''@, @" "@ is not supported. ---- I have carried a carriage return and passed the test in win.
4.2.5 The variable prefix [string] $ a, [int32] $ a is not supported.
4.3bug:
4.3.1 else and elseif cannot be placed at the beginning of the line. ----- This bug has been fixed
--------------- 5 pash comments -----------------
It is really bad if get-content is not supported. But in this case, will the martial arts be useless?
Fortunately, the new-alias and $ profile Functions of alias are good, so that we can use native linux commands to create aliases.
For example, echo "new-alias get-content-linux/usr/bin/cat">/root/. Pash_profile.ps1 # The root here is changed based on the user name.
In this way, we have the get-content-linux Command, and all our martial arts are 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 $ file to be processed = '/etc/ sysconfig/network-scripts/ifcfg-Lo' $ files in each row = get-content-linux $ foreach ($ temp in $ files in each row) {$ temp2 = $ temp2 + 'aaa' + $ temp + "'r'n'"} out-file $ temp2/root/ttt.txt-encoding utf8
--------------- 7 pash installation -----------------
7.1 install mono
7.2 git and pash Compilation
See the previous post http://www.cnblogs.com/piapia/p/4279253.html
--------------- A thousand words into one sentence :-----------------------
I hope you will study more, pay more attention to powershell, pay more attention to pash, and share more ~~~ Septem