perl -we '$s=;print quotemeta $s'
Run this, then type (or paste) in any command, and it will print out an escaped version of the entered code that can then be aliased.For example, to make the aobve brief perl script into an alias itself, we'll run it at the command line. It then expects you to type a single line of text followed by a carriage return. In this case, I will cut and paste the command itself. This then returns:
perl\ \-we\ \'\$s\=\ \<\>\ \;\ print\ quotemeta\ \$s\'\
Then we can type (cut and paste) the above into an alias like this:
alias qm perl\ \-we\ \'\$s\=\ \<\>\ \;\ print\ quotemeta\ \$s\'\
And voila, we now have a command to meta-escape any future commands we want to aliias. In particular, the script in the hint I previously submitted needs to be metaquoted:
qm perl -we 'die unless @ARGV;$SIG{INT} =sub {`kill -s CONT $p`; die qq:bye now\n:};($p,$s,$c) = ( @ARGV,2.5,0.5);($sig,$w) = (qq:CONT:,30);$c1=$c2=$e1=$e2=0;$e2=30;while (1) { last unless grep{ /^\s*$p /} `ps x`; ($x,$y,$z) = split /\s+/,`sysctl vm.loadavg`; ($sig,$w,$e1,$e2) =(qq:CONT:,30,0,30) if ($z<$c);($sig,$w,$e1,$e2)=(qq:STOP:,300,300,0) if ($y>$s) ; `kill -s $sig $p` ; print STDERR qq/ $p: $x $y $z $sig S:$c1 C:$c2 sec /,chr(13); sleep $w;$c1+=$e1;$c2+=$e2}'This produces:
perl\ \-we\ \'die\ unless\ \@ARGV\;\$SIG\{INT\}\ \=sub\ \{\`kill\ \-s\ CONT\ \$p\`\;\ die\ qq\:bye\ now\\n\:\}\;\(\$p\,\$s\,\$c\)\ \=\ \(\ \@ARGV\,2\.5\,0\.5\)\;\(\$sig\,\$w\)\ \=\ \(qq\:CONT\:\,30\)\;\$c1\=\$c2\=\$e1\=\$e2\=0\;\$e2\=30\;while\ \(1\)\ \{\ last\ unless\ \ grep\{\ \/\^\\s\*\$p\ \/\}\ \`ps\ x\`\;\ \ \(\$x\,\$y\,\$z\)\ \=\ split\ \/\\s\+\/\,\`sysctl\ vm\.loadavg\`\;\ \ \(\$sig\,\$w\,\$e1\,\$e2\)\ \=\(qq\:CONT\:\,30\,0\,30\)\ if\ \(\$z\<\$c\)\;\(\$sig\,\$w\,\$e1\,\$e2\)\=\(qq\:STOP\:\,300\,300\,0\)\ if\ \(\$y\>\$s\)\ \;\ \`kill\ \-s\ \$sig\ \$p\`\ \;\ print\ STDERR\ qq\/\ \$p\:\ \$x\ \$y\ \$z\ \ \ \$sig\ \ S\:\$c1\ C\:\$c2\ sec\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \/\,chr\(13\)\;\ sleep\ \$w\;\$c1\+\=\$e1\;\$c2\+\=\$e2\}\'\Which we can now cut and paste into an alias.
[robg adds: I really hope I didn't mess up any of the quoting when editing the script; I'm pretty sure I didn't, as it seemed to work in my testing, but who knows...]

