stands ready.
whoppers candy in the wait of the question
How do I make a bash script (or any other shell script for that matter) that passes its arguments *completely unchanged* to a python script?
So that typing "shellscriptname stuff" does exactly what "python /long/complex/path/
pythonscriptname.py stuff" does...
... even if "stuff" has like quotation marks and dots and stars and whatnot init?
the impression so far that it's not actually possible, sigh...
i did that for Perl before...
something like: exec (path to python) %1
When you enter a command with stars, the shell will usually expand them before the script sees them, unless you escape or 'quote' them.
$# is apparently any number of arguments
try and do echo $# in your bash script, then if it works, it should be able to pass them to your python executable using exec
E.g. this command will print "*?": echo '*?' -- or this would do the same: echo \*\?
That's the hard part. The script itself is simple: python /long/complex/path/
pythonscriptname.py "$@"
I've always found chocolate to be helpful!
"$@" expands into all the args that were passed to the script, but each one is put in quotes to preserve grouping, which is usually best
or failing that - a baseball bat!
To clarify: use the single quotes when you're typing in the command (shellscriptname 'stuff'), and use "$@" in the script.
Yeah, that was one of the things we tried. Doesn't work, though, when there are double-quotes containing blanks in the argument string.
... and you have to get users to remember to put single quotes around everything.
... I mean, when there are double-quoted scripts containing blanks. You know...
if I do scriptname ' -a "foo bar" '
it arrives at the actual script weirdly tokenized, and causes an error, whereas
/path/to/actual/script -a "foo bar"
amazed at how hard this is.
I mean, isn't this the very first thing one wants to write a script
*for*? To just function as an alias?
Have you considered just making an alias? alias scriptname="/path/to/actual/script"
Nods. Should probably consider that approach; user will have to run an "install program" or something to set up alias, rather than just...
... copying files around, but may be the best solution.
had a certain amount of success using Python script that passes arglist along to real script via Popen. shell still expands "*", but...
... everything else seems to work.
goes off to try alias approach.
you can't do what you want - the shell you type the command into will always do things like expansions, matching, etc.
to the arguments, I don't know of a way to get what the shell saw before it mangled it
agrees, and is thinking more an' more that a shell alias is the way to go; no pre-mangling occurs there I don't think.
getting a headache trying to solve this.
more chocolate
Michele now and nomnoms while flipping through her bash and korn shell books
just cracked it .. yes it is possible
The code!, perhaps sorta ugly, but it does actually work.
That was fun.
Thanks, Lexi! I may actually use that. Or the Python equivalent. Or a shell alias...