Windows Vista Forums

PowerShell and the semicolon

  1. #1


    Larry__Weiss Guest

    PowerShell and the semicolon

    The use of the semicolon in PowerShell is described as a statement separator,
    and it certainly can be demonstrated that it is exactly that when more than one
    command exists on a line. For example,

    echo "aaa"; echo "bbb"; echo "ccc"

    Is there more to tell?

    I'm still puzzled over the difference in these two constructions, the first as
    two lines, and then the same commands separated by a semicolon in one line.

    pwd;
    dir | Select-Object @{e={"$_"}} | fw -c 8

    pwd; dir | Select-Object @{e={"$_"}} | fw -c 8

    It seems that the semicolon is allowing some a pipeline to affect the
    Select-Object cmdlet when it is on the same line, but does not have that effect
    on a separate line.

    I'm used to thinking of command separators as lexical only ideas, but there's
    something else going on here.

    - Larry



      My System SpecsSystem Spec

  2. #2


    tojo2000 Guest

    Re: PowerShell and the semicolon

    On Aug 29, 10:31*am, Larry__Weiss <l...@xxxxxx> wrote:

    > The use of the semicolon in PowerShell is described as a statement separator,
    > and it certainly can be demonstrated that it is exactly that when more than one
    > command exists on a line. *For example,
    >
    > * *echo "aaa"; echo "bbb"; echo "ccc"
    >
    > Is there more to tell?
    >
    > I'm still puzzled over the difference in these two constructions, the first as
    > two lines, and then the same commands separated by a semicolon in one line.
    >
    > * *pwd;
    > * *dir | Select-Object @{e={"$_"}} | fw -c 8
    >
    > * *pwd; dir | Select-Object @{e={"$_"}} | fw -c 8
    >
    > It seems that the semicolon is allowing some a pipeline to affect the
    > Select-Object cmdlet when it is on the same line, but does not have that effect
    > on a separate line.
    >
    > I'm used to thinking of command separators as lexical only ideas, but there's
    > something else going on here.
    >
    > * - Larry
    That is strange. As a general rule I don't use the semicolon unless I
    absolutely have to, even in a foreach-object scriptblock just for
    readability's sake, so I've never run into that.

      My System SpecsSystem Spec

  3. #3


    Larry__Weiss Guest

    Re: PowerShell and the semicolon

    I've narrowed it down to the difference in these two sequences

    PS C:> set-location; get-childitem
    PS C:> get-location; get-childitem

    Why would get-childitem return different results depending of whether the last
    command on the line was set-location or get-location ?

    The
    PS C:> get-location; get-childitem
    case is the one I don't understand.

    I'm using V2 CTP3 and XP.

    - Larry

    Larry__Weiss wrote:

    > The use of the semicolon in PowerShell is described as a statement
    > separator, and it certainly can be demonstrated that it is exactly that
    > when more than one command exists on a line. For example,
    >
    > echo "aaa"; echo "bbb"; echo "ccc"
    >
    > Is there more to tell?
    >
    > I'm still puzzled over the difference in these two constructions, the
    > first as two lines, and then the same commands separated by a semicolon
    > in one line.
    >
    > pwd;
    > dir | Select-Object @{e={"$_"}} | fw -c 8
    >
    > pwd; dir | Select-Object @{e={"$_"}} | fw -c 8
    >
    > It seems that the semicolon is allowing some a pipeline to affect the
    > Select-Object cmdlet when it is on the same line, but does not have that
    > effect on a separate line.
    >
    > I'm used to thinking of command separators as lexical only ideas, but
    > there's something else going on here.
    >

      My System SpecsSystem Spec

  4. #4


    Larry__Weiss Guest

    Re: PowerShell and the semicolon

    Also contrast

    PS C:> get-location; get-childitem
    PS C:> get-location; get-childitem | more

    I'm starting to be convinced this indicates a bug.

    Can anyone reproduce it using PS V2 RTM ?

    - Larry


    Larry__Weiss wrote:

    > I've narrowed it down to the difference in these two sequences
    > PS C:> set-location; get-childitem
    > PS C:> get-location; get-childitem
    > Why would get-childitem return different results depending of whether
    > the last command on the line was set-location or get-location ?
    > The
    > PS C:> get-location; get-childitem
    > case is the one I don't understand.
    > I'm using V2 CTP3 and XP.
    >
    > Larry__Weiss wrote:

    >> The use of the semicolon in PowerShell is described as a statement
    >> separator, and it certainly can be demonstrated that it is exactly
    >> that when more than one command exists on a line. For example,
    >> echo "aaa"; echo "bbb"; echo "ccc"
    >> Is there more to tell?
    >> I'm still puzzled over the difference in these two constructions, the
    >> first as two lines, and then the same commands separated by a
    >> semicolon in one line.
    >> pwd;
    >> dir | Select-Object @{e={"$_"}} | fw -c 8
    >> pwd; dir | Select-Object @{e={"$_"}} | fw -c 8
    >> It seems that the semicolon is allowing some a pipeline to affect the
    >> Select-Object cmdlet when it is on the same line, but does not have
    >> that effect on a separate line.
    >> I'm used to thinking of command separators as lexical only ideas, but
    >> there's something else going on here.
    >>

      My System SpecsSystem Spec

  5. #5


    Bob Landau Guest

    Re: PowerShell and the semicolon

    I believe it to be a bug also. This does repro on what should be the RTM for
    Win7

    A little more insight look at the helpfile for both Get-Location/Set-Location
    Look at the type and members returned from each i.e.

    (Get-Location).gettype()
    Get-Location | Get-Member

    You've learned a-lot but to go beyond where you are these need to be part of
    your toolset.

    As with most Get/Set properties in any language Set returns nada.

    If it weren't for the fact that this caused an out right error I'd think
    this to be a low Severity/Priority bug

    get-location; get-childitem | fl

    I still think this to be a low priority bug; but a bug is a bug.

    Like Tojo2000 I never use semi-colons unless I need to which is close to
    never.


    "Larry__Weiss" wrote:

    > Also contrast
    >
    > PS C:> get-location; get-childitem
    > PS C:> get-location; get-childitem | more
    >
    > I'm starting to be convinced this indicates a bug.
    >
    > Can anyone reproduce it using PS V2 RTM ?
    >
    > - Larry
    >
    >
    > Larry__Weiss wrote:

    > > I've narrowed it down to the difference in these two sequences
    > > PS C:> set-location; get-childitem
    > > PS C:> get-location; get-childitem
    > > Why would get-childitem return different results depending of whether
    > > the last command on the line was set-location or get-location ?
    > > The
    > > PS C:> get-location; get-childitem
    > > case is the one I don't understand.
    > > I'm using V2 CTP3 and XP.
    > >
    > > Larry__Weiss wrote:

    > >> The use of the semicolon in PowerShell is described as a statement
    > >> separator, and it certainly can be demonstrated that it is exactly
    > >> that when more than one command exists on a line. For example,
    > >> echo "aaa"; echo "bbb"; echo "ccc"
    > >> Is there more to tell?
    > >> I'm still puzzled over the difference in these two constructions, the
    > >> first as two lines, and then the same commands separated by a
    > >> semicolon in one line.
    > >> pwd;
    > >> dir | Select-Object @{e={"$_"}} | fw -c 8
    > >> pwd; dir | Select-Object @{e={"$_"}} | fw -c 8
    > >> It seems that the semicolon is allowing some a pipeline to affect the
    > >> Select-Object cmdlet when it is on the same line, but does not have
    > >> that effect on a separate line.
    > >> I'm used to thinking of command separators as lexical only ideas, but
    > >> there's something else going on here.
    > >>
    >

      My System SpecsSystem Spec

  6. #6


    Larry__Weiss Guest

    Re: PowerShell and the semicolon

    I see from that report
    Resolved 7/3/2006 4:38:33 PM
    yet
    Resolved (Postponed)

    Did someone lose track of a code change? That's over 3 years ago!

    - Larry


    Keith Hill [MVP] wrote:

    > This bug was submitted quite a while ago. Feel free to vote on it (link
    > below). Unfortunately it was postponed and not fixed in Windows 7 RTM.
    > https://connect.microsoft.com/feedba...&wa=wsignin1.0
    >
    >
    > "Larry__Weiss" <lfw@xxxxxx> wrote in message
    > news:##2GO6MKKHA.3632@xxxxxx

    >> The use of the semicolon in PowerShell is described as a statement
    >> separator, and it certainly can be demonstrated that it is exactly
    >> that when more than one command exists on a line. For example,
    >>
    >> echo "aaa"; echo "bbb"; echo "ccc"
    >>
    >> Is there more to tell?
    >>
    >> I'm still puzzled over the difference in these two constructions, the
    >> first as two lines, and then the same commands separated by a
    >> semicolon in one line.
    >>
    >> pwd;
    >> dir | Select-Object @{e={"$_"}} | fw -c 8
    >>
    >> pwd; dir | Select-Object @{e={"$_"}} | fw -c 8
    >>
    >> It seems that the semicolon is allowing some a pipeline to affect the
    >> Select-Object cmdlet when it is on the same line, but does not have
    >> that effect on a separate line.
    >>
    >> I'm used to thinking of command separators as lexical only ideas, but
    >> there's something else going on here.
    >>
    >> - Larry
    >

      My System SpecsSystem Spec

  7. #7


    Larry__Weiss Guest

    Re: PowerShell and the semicolon

    Using the form of the example from the duplicate of 152205, issue 333752
    https://connect.microsoft.com/PowerS...dbackID=333752
    (but without using a script), I can duplicate the bug.

    PS C:> get-acl; get-acl | Format-List

    There must be some intrinsic sameness somehow to executing commands separated by
    semicolons, and executing commands in sequence in a script that allows this bug
    to be exposed by either structure.

    PS C:> &{

    >> get-acl
    >> get-acl | Format-List
    >> }
    >>
    will cause it as well.

    - Larry


    Keith Hill [MVP] wrote:

    > This bug was submitted quite a while ago. Feel free to vote on it (link
    > below). Unfortunately it was postponed and not fixed in Windows 7 RTM.
    > https://connect.microsoft.com/feedba...&wa=wsignin1.0
    >
    > "Larry__Weiss" <lfw@xxxxxx> wrote in message
    > news:##2GO6MKKHA.3632@xxxxxx

    >> The use of the semicolon in PowerShell is described as a statement
    >> separator, and it certainly can be demonstrated that it is exactly
    >> that when more than one command exists on a line. For example,
    >>
    >> echo "aaa"; echo "bbb"; echo "ccc"
    >>
    >> Is there more to tell?
    >>
    >> I'm still puzzled over the difference in these two constructions, the
    >> first as two lines, and then the same commands separated by a
    >> semicolon in one line.
    >>
    >> pwd;
    >> dir | Select-Object @{e={"$_"}} | fw -c 8
    >>
    >> pwd; dir | Select-Object @{e={"$_"}} | fw -c 8
    >>
    >> It seems that the semicolon is allowing some a pipeline to affect the
    >> Select-Object cmdlet when it is on the same line, but does not have
    >> that effect on a separate line.
    >>
    >> I'm used to thinking of command separators as lexical only ideas, but
    >> there's something else going on here.
    >>
    >> - Larry
    >

      My System SpecsSystem Spec

  8. #8


    Thomas Lee Guest

    Re: PowerShell and the semicolon

    In message <558222E4-3984-49C4-A59A-A8605DF84F9C@xxxxxx>, "Keith
    Hill [MVP]" <r_keith_hill@xxxxxx> writes

    >This bug was submitted quite a while ago. Feel free to vote on it
    >(link below). Unfortunately it was postponed and not fixed in Windows
    >7 RTM.
    >
    >https://connect.microsoft.com/feedba...eedbackID=1522
    >05&SiteID=99&wa=wsignin1.0
    v & v!

    --
    Thomas Lee
    doctordns@xxxxxx

      My System SpecsSystem Spec

  9. #9


    Larry__Weiss Guest

    Re: PowerShell and the semicolon

    See recent discussion under the thread "Powershell bug, MS refuses to fix.".

    Perhaps it is not a bug after all!

    As I suspected, there is "more to tell".

    - Larry


    Keith Hill [MVP] wrote:

    > This bug was submitted quite a while ago. Feel free to vote on it (link
    > below). Unfortunately it was postponed and not fixed in Windows 7 RTM.
    >
    > https://connect.microsoft.com/feedba...&wa=wsignin1.0
    >
    >
    > --
    > Keith
    >
    > "Larry__Weiss" <lfw@newsgroup> wrote in message
    > news:##2GO6MKKHA.3632@newsgroup

    >> The use of the semicolon in PowerShell is described as a statement
    >> separator, and it certainly can be demonstrated that it is exactly
    >> that when more than one command exists on a line. For example,
    >>
    >> echo "aaa"; echo "bbb"; echo "ccc"
    >>
    >> Is there more to tell?
    >>
    >> I'm still puzzled over the difference in these two constructions, the
    >> first as two lines, and then the same commands separated by a
    >> semicolon in one line.
    >>
    >> pwd;
    >> dir | Select-Object @{e={"$_"}} | fw -c 8
    >>
    >> pwd; dir | Select-Object @{e={"$_"}} | fw -c 8
    >>
    >> It seems that the semicolon is allowing some a pipeline to affect the
    >> Select-Object cmdlet when it is on the same line, but does not have
    >> that effect on a separate line.
    >>
    >> I'm used to thinking of command separators as lexical only ideas, but
    >> there's something else going on here.
    >>
    >> - Larry
    >

      My System SpecsSystem Spec

PowerShell and the semicolon

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I use Import-CSV when separator is semicolon? David Kriz PowerShell 3 04 Aug 2008
when run powershell script as windows service ,powershell fail powershell fail on winodws 2008 PowerShell 6 15 Jan 2008
Powershell Plus - Free for non commercial Use and Powershell Analyzer1.0 released Karl Prosser[MVP] PowerShell 2 12 Dec 2007
Automatic PowerShell Error Parsing in PowerShell Analyzer and PowerShellPlus Karl Prosser[MVP] PowerShell 0 14 Nov 2007
PowerShell Leaders Join Forces and offer a pre-release version of PowerShell for 50% off the retail value klumsy@xtra.co.nz PowerShell 0 19 Jun 2007