The "shellcmd" macro
Usage
The {shellcmd} macro takes several optional parameters.
Parameter | What it does |
---|---|
prompt=someprompt | Specify the shell prompt. If not specified, it defaults to "athena%" |
cmd=the command | Specify the command the user will type. This is boldfaced. |
italics=words italics=word1,word2 |
Specify portions of the command that should be italicized to indicate that the user should replace them with actual information. Comma-separated. |
split=true | if set to "true", semicolons in the "cmd" parameter will be separated out into new lines (see below) |
The macro has a body, which will be displayed below the command to represent output. Output will be displayed with the "noformat" wiki markup to retain ASCII formatting. You can omit the body if it's just a one-line command, but you still need to supply a closing "{shellcmd}"
NOTE: The pipe character (|) cannot be used. Use the string "[~jdreed:pipe]" instead, which will be replaced by the macro. Curly braces ({ }) must be escaped with backslashes
Some examples
One italicized parameter and output
Code
{shellcmd:cmd=ssh username@athena.dialup.mit.edu|italics=username} The authenticity of host 'athena.dialup.mit.edu' can't be established. RSA key fingerprint is 43:75:37:88:1c:f9:07:d8:b5:ce:73:51:0e:28:07:ef. {shellcmd}
Result
joeuser@athena:~$ ssh username@athena.dialup.mit.edu
The authenticity of host 'athena.dialup.mit.edu' can't be established. RSA key fingerprint is 43:75:37:88:1c:f9:07:d8:b5:ce:73:51:0e:28:07:ef.
Note: Be sure to fill in the correct information for username.
Two italicized parameters, no output
Code
{shellcmd:cmd=ssh username@hostname:/tmp|italics=username,hostname} {shellcmd}
Result
joeuser@athena:~$ ssh username@hostname:/tmp
Note: Be sure to fill in the correct information for username and hostname.
Specifying the prompt, using special characters in the command
Code
{shellcmd:cmd=cat /proc/version [pipe] awk '\{print $1\}'|prompt=bash-3.00$} Linux {shellcmd}
Result
bash-3.00$ cat /proc/version | awk '{print $1}'
Linux
Using semicolons for multiple commands
Code
{shellcmd:cmd=add consult; lastupd|split=true} {shellcmd}
Result
joeuser@athena:~$ add consult
joeuser@athena:~$ lastupd
joeuser@athena:~$ lastupd
And now for something completely different
Code
{shellcmd:cmd=dir|prompt=C:\WINDOWS>} {shellcmd}
Result
C:WINDOWS> dir
Macro source code
shellcmd user macro
## Macro to display shell commands in articles. ## Last updated: jdreed, 2 / 9 / 09 ## Prompt defaults to "athena%" unless specified ## The 2nd "set" below does not change $prompt unless ## $paramprompt is not null #set ($prompt = "athena%" ) #set ($prompt = $paramprompt ) #set ($cmd = $paramcmd.replace( "[pipe]" , "|" )) #set ($replacetxt = $paramitalics.replace( "," , "</em> and <em>" )) # if ($replacetxt) #set ($replacetxt = "<em>${replacetxt}</em>" ) #end #foreach( $item in $paramitalics.split( "," ) ) #set ($cmd = $cmd.replace( "$item" , "<em>$item</em>" )) #end <div class = "preformatted panel" style= "border-width: 1px;" > <div class = "preformattedContent panelContent" > # if ($paramsplit == "true" ) #set ($cmd = $cmd.replace( ";" , "<br>;" ) ) #foreach ($cmdline in $cmd.split( ";" ) ) <tt>$prompt <b>$cmdline</b></tt> #end # else <tt>$prompt <b>$cmd</b></tt> #end <pre>$body</pre> </div> # if ($replacetxt) <div class = "panelContent" > Note: Be sure to fill in the correct information for $replacetxt. </div> #end </div> |