I am going to hell
If you thought my previous bash alias hacks were evil, don't even read this one.
Given these definitions …
echo-literally-helper() {
str="`history 1 | perl -pe 's/^ *[0-9]+ +[^ ]+ //'`"
echo "$str"
}
alias echo-literally='echo-literally-helper #'
… the alias echo-literally will now pass its completely uninterpreted command line to the shell function echo-literally-helper. My previous magic-alias mechanism allowed you to prevent or fiddle with wildcard expansion, to alter the values of environment variables and one or two other useful things, but this is an order of magnitude more powerful:
$ echo-literally a; b; c
a; b; c
$ echo-literally a
a
$ echo-literally hello, world > thingy
hello, world > thingy
$ echo-literally ooh # this is a comment
ooh # this is a comment
Of course, this technique isn't limited to printing the command line string verbatim. The shell function gets hold of the text as a string variable, and can process it in any way it sees fit; so you could feed it back to the shell argument parsing if you really wanted (perhaps after modifying some settings which you wouldn't be able to modify using the other mechanism), or have it parsed by a different shell, or do whatever you like with it.
And just like my previous magic-aliases trick, there are limitations. This monstrosity only works when typed at an interactive command line, since otherwise the command doesn't find its way into the history list to be recovered; and also it will break down if you precede it on the line with any other command.
But even so, it's pretty cool, in a genuinely horrifying sort of way. I developed it for my colleague Charlie, who wanted it for use in an rsh-like sort of mechanism (having to quote the complex command line you're passing to the server can be a real pain). I wonder if there are any other particularly fun uses for it.
no subject
no subject
no subject
It all gets a bit mucky; because you're explicitly breaking the parse of the command line, you have to make rather arbitrary decisions about whether to be greedy or not, given something like:
echo `echo-literally foo; bar; baz` ; echo `foo bar`
or
echo $(echo-literally foo; bar; baz) $(echo foo; bar; baz)
no subject
$(...)constructions on a single line, there's no way for the execution of either one to know which of them is meant. I can't see any possible way to makework at all.no subject
There is a command line tool (gst-launch) to set up a gstreamer pipeline, which currently uses !'s instead of |'s to separate elements. They could use this method to provide an alternative syntax using |'s.
It might not play well with their tab-expansion system, though.
no subject
no subject
Cool.
I'm puzzled by the temporary variable - why not:
echo-literally-helper() { history 1 | perl -pe 's/^ *[0-9]+ +[^ ]+ //' }no subject
$str, you can do further string processing on it in any fashion you like. Theechocommand is really a placeholder for "now do stuff of your choice with".no subject
### Some stuff to setup $prefix
x=$1
while [[ $x -le $2 ]]
do
echo ${prefix}${x}
ox=$x
x=$(( $x + 1 ))
if [[ $x < $ox ]]
then
prefix=$( echo $prefix | cut -c 2- )
fi
done
no subject
I am now fore-warned...
no subject