Pash Console Arguments Issue

74 views
Skip to first unread message

Joaquin Menchaca

unread,
Aug 17, 2014, 7:15:11 PM8/17/14
to pash-p...@googlegroups.com
I noticed that if I try to run a script like this:

./myscript.ps1

I get a message from pash that ./myscript.ps1 cannot be found. I hope we can accept arguments to pash that are like this, because this is how you essentially run scripts on Unix/Linux.

My Shebang line is the following:

#!/usr/bin/env pash

Which is

/usr/bin/pash

This itself is a script:

mono /Users/joaquinmenchaca/pubarea/Pash/Source/PashConsole/bin/Debug/Pash.exe $@

As an alternative, I do a pash myscript.ps1 to run the script.

Johannes Rössel

unread,
Aug 18, 2014, 1:48:08 AM8/18/14
to pash-p...@googlegroups.com
Hello Joaquin,

(I'm talking about PowerShell throughout here because I'm describing
behaviour we don't yet have in Pash but eventually will.)

On 2014-08-18 01:15, Joaquin Menchaca wrote:
> My Shebang line is the following:
>
> *#!/usr/bin/env pash*

Technically you would need to include the -File parameter here. This is
because PowerShell otherwise interprets its argument as a command to
run. This *does* work for invoking a script *sometimes*. But there is a
subtle difference.

-File takes the next argument and knows it has to be a script file, and
if it's not qualified with an absolute path the search will be from the
current working directory. This happens in the current working directory
given by the system.

If you have a profile that sets a different directory (e.g. my own
profile creates a new drive Home: that's mapped to ~ and does a
Set-Location there), then the method *without* -File would fail, because
PowerShell then starts, loads its profile and then tries to execute the
command. Worse, it will run a completely different script if you happen
to have one with the same name in the directory it starts up with.

My own scripts usually run with the following invocation:

powershell -noprofile -file ...

This allows me to write scripts that stay in the current directory and
do things there (as I said, my profile changes it) and also forces me to
write scripts that run everywhere by using only default aliases. For me
the profile is more something that makes interactive use nicer, not a
base for scripts.

I don't know how to pass additional parameters in a shebang line as the
one you have there currently, though. I have no idea what env does with
them if you just stick them at the end.

Regards,
Johannes

Stefan Burnicki

unread,
Aug 18, 2014, 8:28:58 AM8/18/14
to pash-p...@googlegroups.com
Hey Joaquin,

there are two issues you are experiencing here:
- The default argument for Pash is currently (as it is in Powershell) to execute a command. Therefore the correct command to pass would be
  "& ./myscript.ps1"
- Executing files (not commands) with the -File parameter is not yet implemented, but it definitely should get implemented.
- Last but not least we have an annoying bug: In Powershell/Pash you can also invoke a script with the "." operartor, meaning that the script is invoked in the same scope.
  Sadly, the parser currently doesn't get the difference between ". /myscript.ps1" and "./myscript.ps1", s.t. a relative path might be interpreted as invoking a script in root path.
  Hopefully, we will fix this issue soon.
Reply all
Reply to author
Forward
0 new messages