108
votes
What is the difference between double and single square brackets in bash?
Behavior differences
Some differences on Bash 4.3.11:
POSIX vs Bash extension:
[ is POSIX
[[ is a Bash extension inspired from Korn shell
regular command vs magic
[ is just a regular command with ...
21
votes
What is the difference between double and single square brackets in bash?
Single Bracket i.e. [] is POSIX shell compliant to to enclose a conditional expression.
Double Brackets i.e. [[]] is an enhanced (or extension) version of standard POSIX version, this is ...
20
votes
How do I read multiple lines from STDIN into a variable?
Try this:
user@host:~$ read -d '' x <<EOF
> mic
> check
> one
> two
> EOF
Without line breaks:
user@host:~$ echo $x
mic check one two
With line breaks:
user@host:~$ echo "$x"
mic
check
one
...
16
votes
Accepted
PowerShell prompt to continue execution of code
Another simple solution would be to use:
Read-Host -Prompt "Press any key to continue or CTRL+C to quit"
I believe this is a better solution to the currently accepted answer because the ...
15
votes
how to find out the valid store names for certutil
You can quickly get the list in Powershell:
PS> ls Cert:\LocalMachine
Name : TrustedPublisher
Name : ClientAuthIssuer
Name : Remote Desktop
Name : Root
Name : TrustedDevices
Name : WebHosting
...
15
votes
Bash script to retrieve name of Ethernet Network interface
Because all interfaces would displayed under /sys/class/, such as /sys/class/net/ listing all network interfaces,
it is possible to directly use this directly search and return the exact interface ...
13
votes
PowerShell prompt to continue execution of code
You Can use write-warning option. quite sleek:
Write-Warning "This is only a test warning." -WarningAction Inquire
WARNING: This is only a test warning.
Confirm
Continue with this operation?
[Y] Yes ...
13
votes
How to edit Local Group Policy with a script?
PolicyFileEditor is a PowerShell module to manage local GPO registry.pol files.
Brandon Padgett provides an example usage:
$RegPath = 'Software\Policies\Microsoft\Windows\Control Panel\Desktop'
$...
13
votes
Accepted
What is difference between */5 and 5 for minute value in crontabs?
5 * * * * means it runs once per hour at five minutes past the hour.
*/5 * * * * means it runs once every five minutes.
The later construct behaves slightly unintuitive if the number does not divide ...
12
votes
Accepted
What version of Windows Management Framework is installed?
See this documentation from Microsoft:
https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell?view=powershell-5.1
In the "Upgrading existing Windows Powershell" ...
12
votes
Accepted
Manage Multiple IIS servers without shared configuration
Configuration Editor within IIS Manager does exactly this.
Creates a script of the actions that you have recently performed. Opens the Script Dialog window that displays the script for your action ...
11
votes
How to add a shutdown script (not by using gpedit.msc or active directory)?
To anyone struggling to get this working, my sympathy. I spent many hours trying to figure out exactly which of the hundreds of changes gpedit makes are actually important. My tests were conducted on ...
11
votes
Accepted
Retrieve internet proxy server address via PowerShell
Here is the PowerShell function to achieve my goal :
function Get-InternetProxy
{
<#
.SYNOPSIS
Determine the internet proxy address
.DESCRIPTION
...
11
votes
Entering local admin username and password in a script
Start your batch:
powershell.exe -Command "Start-Process cmd -Verb RunAs"
...
rest of script
...
This will open an elevated command prompt
Keep in mind for this to work the user would need to have ...
10
votes
How can I easily convert HTML special entities from a standard input stream in Linux?
recode seems available on default packages repositories of main GNU/Linux distributions. E.g. to decode HTML entities into UTF-8 :
…|recode html..utf8
10
votes
What version of Windows Management Framework is installed?
I know this is an old question, but for others that find this from a Google Search:
I would like to argue that $PSVersionTable.PSVersion is the most reliable indicator of the version of WMF. See ...
10
votes
Retrieve internet proxy server address via PowerShell
[System.Net.WebProxy]::GetDefaultProxy() | select address
[System.Net.WebProxy] is an object and one of its static methods is GetDefaultProxy(). The select shows for us from all the columns, what ...
10
votes
How to edit Local Group Policy with a script?
You can do it in PowerShell using Set-ItemProperty on the Registry provider; e.g. to disable Windows Update Access, you can run:
Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\...
9
votes
How to use a config file (ini, conf,...) with a PowerShell Script?
There is a much more convenient way to read settings from JSON-file using the ConvertFrom-Json Cmdlet in PowerShell to read a JSON formatted file:
$SettingsObject = Get-Content -Path \path\to\settings....
9
votes
Error handling in Mikrotik scripts
UPDATE as of RouterOS v6.2
You can now create a do block with an error handler:
:do {
/tool fetch $url
:put "Fetch OK"
} on-error={ :put "Fetch ERROR"};
9
votes
Accepted
How to check that all ZFS snapshots within a pool are without holds before destroying that pool
Not sure about how this looked back in 2012 but now you can check the userrefs property:
zfs get userrefs
To list all holds in all pools:
zfs get -Ht snapshot userrefs | grep -v $'\t'0 | cut -d $'\...
9
votes
How to output a list of changed files from rsync?
This question is a little bit old, but I think it worth to be added:
-i is a shortcut of --out-format=%i%n%L
And %n means the filename, (section log format of man rsyncd.conf)
P.S. rsync version 3....
9
votes
How can I run arbitrarily complex command using sudo over ssh?
UPDATE: Examples now explicitly use sudo.
Here's a way to use Bash syntax with compound assignments to execute arbitrarily complex commands over SSH with sudo:
CMD=$( cat <<'EOT'
echo "...
9
votes
Accepted
How to get SCCM to recognize return codes from Powershell script completion?
There is a known problem with powershell exit codes (see the end of this answer) that can manifest when using powershell installation scripts with SCCM. To workaround the problem, I take two measures:...
9
votes
Accepted
Can't Store NGinx Version to Variable
nginx writes its version info to stderr not stdout so to capture it you'll need to redirect it like
nginx_version=$(nginx -v 2>&1)
or
nginx -v 2> /home/user/nginxversion.txt
Also, note ...
9
votes
Accepted
Bash script to retrieve name of Ethernet Network interface
If you want to exclude interfaces like vir , loopback and wl(wireless) then the following should do the trick.
ip link | awk -F: '$0 !~ "lo|vir|wl|^[^0-9]"{print $2;getline}'
Here we use ...
7
votes
how to find out the valid store names for certutil
This will enumerate all certificate stores:
certutil -enumstore
certutil -enumstore output
Check this answer for naming discrepancies:
Certutil naming mismatch
7
votes
Using curl with cookies
It is possible that their website is authenticating the session stored in the cookies by redirecting them first to the login page. Then their login page will redirect back to the appropriate page as ...
7
votes
Accepted
What is the best way to get a list of nodes that belong to a Cassandra cluster?
You can use the nodetool status command with awk:
nodetool status | awk '/^(U|D)(N|L|J|M)/{print $2}'
Each line that contains information about a node will either start with the Status of the node ...
7
votes
What shebang for Anaconda Python on my directory of Server
To add to the already accepted answer (and reply to 0xc0de's comment), I think we can use:
#!/usr/bin/env python
Then we need to activate the Conda environment, or source the custom Python path that ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
scripting × 1820bash × 391
linux × 334
powershell × 274
windows × 256
shell × 126
active-directory × 78
shell-scripting × 65
batch × 63
cron × 58
ssh × 55
windows-server-2003 × 55
automation × 55
ubuntu × 54
windows-server-2008 × 50
command-line-interface × 50
networking × 48
group-policy × 47
batch-file × 44
centos × 41
python × 38
unix × 33
vbscript × 33
email × 31
windows-server-2008-r2 × 30