Freigeben über


More, no less!?

First question, does LS work?! I am happy to say the answer is yes as you can see from the screen shot (Fig 1.1)  LS prints out the contents of the current directory in a nice neat way. Re-direction of text and piping work too, but with an added twist. Unlike BASH piping in MSH is down via objects and not strings. Enough fluff, lets load up the command shell and get coding.

fig.1.1

First things first, Strings: Type:

“This is MSH”

Into the shell and press return. This will echo out the string to the command line. It’s a start, so what more can we do with strings? Well, I am going to take a bit of a guess here and try:

“This is MSH”.length
 
As I know from .NET this should return the amount of characters in the string. Luckily for me, it works! The number 11 is printed on the terminal. So what else can we do to these string objects? Luckily the Reflection namespace provides us with a very useful function “GetMember” that returns all the methods and properties available in a specific .NET object (https://www.devx.com/tips/Tip/21232). Let’s try it!

“This is MSH” | get-member

This returns a long list of different methods that are available to the string class. Equals, ToUpper and all our favourite methods are available.  So, we can play with strings and get methods associated with it. So what about variables? Well using the $ and = sign it is possible to assign values to variables:

$strMSH = “This is MSH”

$val = 5

All work as you would expect. So what about combining strings and variables. Let’s try:

$var = “This is MSH”.Split(“ “)

foreach($str in $var)
{
if($str.Equals(“MSH”))
{
“Monad”
}
else
{
$str
}
}

As we can see we split the string down into an array, and then print out each value of the string replacing MSH with monad! So we have conditionals, loops and the power of .NET built into MSH what more could you want?

 I hope this has given you a flavour for what is currently possible with the beta version of MSH and it can only get more powerful. Having come into this wondering if it would be possible to give BASH a run for its money, I have come out very impressed and looking forward to the day when MSH is the default shell in Windows.

Here is a simple little challenge for you, what does the following snippet of code do?

$first = 1;
$second = 1;
for($i = 0; $i -lt 50; $i++)
{
$last
$last = $first + $second;
$first = $second;
$second = $last;
}

Why not post an answer on the Mint Source Student Blog? Blogs.msdn.com/ukstudentzine

Comments

  • Anonymous
    March 07, 2006
    So my journey of learning Monad continues, and I'm now in the realm of variables, functions and control...
  • Anonymous
    March 09, 2006
    After a bumper edition of the student newsletter, I thought it would be a great idea to share some of...