Archive for the ‘tips’ Category

Windows command escape character

Apparently the escape character for cmd.exe is ^.

So if you want to do the equivalent of echo "\$PATH = $PATH" in Windows, you would do echo "^%PATH^%=%PATH%"

In PowerShell, things are a bit different. They decided to change the variable identifier to $, which is nice and consistent with unix. Still didn’t use the \ character for escaping, though. The reason is that it overlaps with the path separator from DOS. So instead, you must use ` (back tick). Of course, this messes with me since in bash back tick is used to execute a command and return the output in to a variable.

See:
CMD.EXE Escape characters
PowerShell Escape Sequences

Killing all child processes in a shell script

If you have a shell script that runs a lot of jobs in the background, you will want to clean these processes up at the end of the execution ( say the user hits CTRL-C or kills the job). To do so is fairly easy if you know how to do it. No need to keep track of pids, just do kill 0 as part of the signal trap execution. eg.

#!/bin/bash

trap "kill 0" SIGINT SIGTERM

runprogram &
otherprogram &

wait

Found at: stackoverflow.com

Killing a stuck SSH or TELNET session

Useful thing I found today. To kill an ssh session that is hung (host down, network outage, etc… while ssh connected), just hit the enter key and type ~.

found at: serverfault.com

Also, to end a telnet session, you do CTRL-] and type quit.

found at: chipkin.com

Return top

INFORMATION

Change this sentence and title from admin Theme option page.