Command Detail - E
echo
echo
is an alias in PowerShell. As you would expect it's an alias for the closest equivalent to the Linux echo
:
write-output
You use it as follows:
As well as write-output there are a couple of options for use in Powershell scripts and functions:
write-debug
write-verbose
Whether these produce any output is controlled by commandline or environment flags.
echo -n
In bash, echo -n
echoes back the string without printing a newline, so if you do this:
you get:
....with your cursor ending up on the same line as the output, just after the dollar prompt
Powershell has an exact equivalent of 'echo -n'. If you type:
....then you get this:
Note that -nonewline
doesn't 'work' if you're in the ISE.
egrep
The best PowerShell equivalent to egrep
or grep
is select-string
:
A nice feature of select-string
which isn't available in grep
is the -context
option. The -context switch allows you to see a specified number of lines either side of the matching one. I think this is similar to SEARCH /WINDOW
option in DCL.
egrep -i
Powershell is case-insensitive by default, so:
...would return:
If you want to do a case sensitive search, then you can use:
egrep -v
The Powershell equivalent to the -v
option would be -notmatch
egrep 'this|that'
To search for more than one string within a file in bash, you use the syntax:
This will return lines which contain either 'blue' or 'stamford'.
The PowerShell equivalent is to seperate the two strings with a comma, so:
...returns:
| egrep -i sql
This is an interesting one, in that it points up a conceptual difference between PowerShell and Bash.
In bash, if you want to pipe into a grep, you would do this:
This would show you all the processes which include the string 'sql' somewhere in the line returned by ps
. The egrep is searching across the whole line. If the username is 'mr_sql' then a line would be returned, and if the process is 'sqlplus' than a line would also be returned.
To do something similar in PowerShell you would do something more specific
So the string 'sql' has to match the contents of the property processname
. As it happens, get-process by default only returns one text field, so in this case it's relatively academic, but hopefully it illustrates the point.
env
The Linux 'env' shows all the environment variables.
In PowerShell there are two set of environment variables:
windows-level variables and
Powershell-level variable
Windows-level variables are given by:
PowerShell-level variables are given by:
errpt
I think errpt is possibly just an AIX thing (the linux equivalent is, I think, looking at /var/log/message
). It shows system error and log messages.
The PowerShell equivalent would be to look at the Windows eventlog, as follows
The lognames that I typically look at are 'system', 'application' or 'security'.
export PS1="$ "
In bash the following changes the prompt when you are at the command line
The Powershell equivalent to this is:
I found this on Richard Siddaway's blog: http://msmvps.com/blogs/richardsiddaway/archive/2013/07/21/fun-with-prompts.aspx
Last updated