SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Parameter Fun

By Steve Jones,

Recently I was editing a document about SQL Server on Linux and the author noted that if you type "sqlcmd" without any parameters, you get the list of possible parameters back. I tried that on my Windows laptop and immediately got an error that no credentials were supplied. Apparently sqlcmd on Windows attempts to connect to the default instance.

I thought the author had made an error, but sure enough, when I connected to Linux and ran just "sqlcmd", I got a list of parameters. What was more fascinating to me was that if I ran "sqlcmd -?" on either platform, I got the parameter list, as I would expect. However, if I ran "sqlcmd /?", this worked on Windows, but returned an error on Linux.

A long time ago I wrote some command line utilities to help our network team manage a Netware 3.x environment. I was proud of my work and knew that the team would appreciate a few of my tools. When I first showed me boss and started to explain what it did, he stopped me and ran the name of the utility with a /? at the end. Nothing returned, and he told me to redo the work and ensure that /? always returned help for the tool.

I've kept that habit for years and I've often tried that with new programs. Most have worked, including bcp and sqlcmd. Somehow, that hasn't continued to this day. For sqlcmd.exe on Linux, only -? works. If you run Docker, you need a --help, though -help works. Other programs might be more strict, but it's surprising to me how many different ways we've implemented help and parameters.

PowerShell has Get-Help, but then uses single dashes for parameters. A number of newer cli tools, especially for Linux, seem to want two dashes for parameters, though a single dash often works. I've seen a few tools that mix single and double dashes, depending on which parameter. I did find this note that on Unix a few single dash parameters can be combined, so the double dash indicates we are using one parameter, not multiple ones. That makes sense, though I would argue that -abc meaning -a -b -c is a fundamental design problem in and of itself.

The evolution of help and parameters seems funny to me. It's likely caused by someone implementing the parameter short cutting in Unix at some point that now requires double dashes for multi-character parameters, which is really a case of a short-sighted design in Unix. In any case, understanding the behavior of parameters and help is a useful skill, especially in the current environment that tends to implement more scripts with command line utilities.

Total article views: 52 | Views in the last 30 days: 52
Related Articles

Passing ServerName as parameter to SQLCMD

Passing ServerName as parameter to SQLCMD


Double hop error when using SQLCMD

tl;dr; SQLCMD v2014 and up has special requirements for Kerberos. One of the problems with linked ...


Invoke-Sqlcmd is Now Available Cross-Platform in the SqlServer module

Invoke-Sqlcmd is Now Available for MacOS & Linux in the SqlServer module.  The module has been poste...


Avoiding confusion with SQLCMD variables

SQLCMD variables can be a useful way of having changeable parameters for your SQL scripts, allowing ...


sqlcmd -S

sqlcmd -S