0

I have gnuwin32 installed and appended to my environment so I run linux/unix "ls" when I type ls in the command prompt. That's not a problem for Powershell, apparently, but I'm not being able to create a custom alias, with both the same name (ls) or a differnt name (lsa/ll/ld), and I'm getting the following error:

The script failed due to call depth overflow.
+ CategoryInfo          : InvalidOperation: (0:Int32) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CallDepthOverflow

Now, here's my Powershell script:

Set-Alias -name ls -value ListDirectory -Option AllScope

Function ListDirectory { 
    $Command = "ls -I ntuser\.* -I NTUSER\.*";
    Invoke-Expression $Command
}

Any ideas? About the ignore files, I need them. Just to make sure, this command works just fine in good old command prompt, I'm only having problems in Powershell :(

2
  • You are creating an infinitive loop. I'd try $Command = "ls.exe -I ntuser\.* -I NTUSER\.*";
    – LotPings
    Jun 9, 2017 at 8:56
  • Good point @LotPings, this may be the answer to my question actually!! I realized I didn't need gnuwin32 though, for now, but should I reinstall it I'll make sure to type .EXE and not just "ls" or "grep" or any other command!! Thanks hipss
    – prubini87
    Jun 9, 2017 at 19:24

1 Answer 1

0

@LotPings You were correct! Adding ".exe" to ls did "the trick". I've added a loop to grab eventual arguments I may wanna pass to it and placed the arguments within my $Command variable. I'm not sure I did this in the best way but it works! Hehe. Thanks again!

# gnuwin32 "ls"
Set-Alias -name ls -value ListDirectory -Option AllScope

Function ListDirectory {
    $allArgs = "";
    For ($i=0; $i -lt $args.Length; $i++) {
        $allArgs += $args[$i] + " ";
    }

    $Command = "ls.exe $allArgs -I ntuser\.* -I NTUSER\.*";
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .