[Feature Request: Linux] - A way to use "-noprofile" when running script directly from shell ( $> ./myscript.ps1 ) using #!/usr/bin/env pwsh
See original GitHub issueHey there, I apologize if there is a way to do this that I am not aware of, but I have not come across info on it if there is.
My request is to have a way to run scripts directly from a shell without loading the items in my $PROFILE.
Currently, I have a PowerShell script I created running on Linux which I use to parse /proc/net/dev to determine the current network rate. As seen in the excerpt below, the script uses the shebang #!/usr/bin/env pwsh
in order to allow me to invoke the script on a schedule easily from Jobber as seen in the second dropdown below. There doesn’t seem to be a way that I am aware of to run the script without the unnecessary overhead of including the loading of my $PROFILE, such as custom prompt and other modules that are only needed/used in an active terminal.
I was attempting to profile the script by watching it in HTOP and noticed that upon each invocation it was somewhere in the neighborhood of 100MB in size and 27 threads, which I thought was a bit excessive. I went into my $PROFILE and commented everything out and right away saw each invocation dropped down to 87MB (still 27 threads). While still pretty heavy, definitely better.
I realize that there is always going to be fairly substantial overhead of running a PowerShell script on Linux compared to simply running a Bash script due to the runtime and all that, but I feel it would definitely help with adoption to be able to run things in a familiar manner without having to exclusively choose between any sort of personal customization and trying to maintain minimal overhead for additional performance in these two situations (me, actively using pwsh in a terminal vs having a script run on a schedule).
All in all, I love being able to have the much more friendly and familiar(to me, at least) coding experience of the .Net ecosystem on my Linux boxes and was hoping to utilize it more often and in different situations, but if each script is going to cost 100MB a pop, it seems that I my thought of replacing a lot of these small random bash scripts on my system with PowerShell scripts may not be the best idea and will end up being much more situational based on need. Either way, though, I really do like at least having the option and ability to do so, at least. 👍
Thanks, -MH
Script Excerpt
#!/usr/bin/env pwsh
<#
.NOTES
======================================================
Created on: 03/24/2021
Created by: instance.id
Platform: Linux
Filename: traffic.ps1
======================================================
.DESCRIPTION
Parses cat /proc/net/dev to determine current network transfer rate
#>
# --------------- Linux current network transfer rate check
# ---------------------------------------------------------
param (
[Parameter()]
[int]$Sleep = 1,
[string]$Device,
[switch]$Human,
[switch]$NoLabel,
[switch]$Pad,
[switch]$Conky
)
Jobber Invocation
jobs:
speed:
cmd: /home/mosthated/.conky/scripts/traffic.ps1 -Device enp6s0 -Sleep 1 -Human -Pad -Conky
time: '*/2 * * * * *'
onError: Continue
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top GitHub Comments
Nice, @237dmitry - didn’t know about the
-S
option for makingenv
split the single argument it is given on Linux into individual arguments, but there’s a caveat:On Linux distros, it requires GNU coreutils v8.30+, which are included with Ubuntu 19.04+, for instance, but not with Ubuntu 18.04 and earlier. In other words: older Linux distros may not support it (though that problem will take care of itself over time).
(On macOS it is supported since at least Catalina; it isn’t necessary there, but does no harm, which makes the solution portable.)
Just to spell out @jborean93’s suggestion:
pwsh-np
(from PowerShell) in/usr/bin
(Linux) //usr/local/bin
(macOS):and
to run it out from pwsh shell.