If I want to run a specific command (with arguments) under Software Collections, I can use this command:
scl enable python27 "ls /tmp"
However, if I try to make a shell script that has a similar command as its shebang line, I get errors:
$ cat myscript
#!/usr/bin/scl enable python27 "ls /tmp"
echo hello
$ ./myscript
Unable to open /etc/scl/prefixes/"ls!
What am I doing wrong?
The parsing of arguments in the she-bang command is not really defined. From
man execve:No matter what, argument splitting based on quote sis not supported. So when you write:
It's very possible that what gets invoked is (using bash notation):
This is probably why it tries to open the
"lsfile at/etc/scl/prefixes/"lsBut it is just as likely that the shebang evaluates to:
And that would fail since it wont be able to find a command named
enable python27 "ls /tmp"for scl to execute.There's a few workarounds you can use.
You can call your script via scl:
You can also use the heredoc notation, but it might lead to subtle issues. I personally avoid this:
You can see one of the gotcha's already: I had to write
\$X_SCLSto access the environment variable instead of just$X_SCL.Edit: Another option is two have two scripts. One that has the actual code, and the second that simply does
scl enable python27 $FIRST_SCRIPT. Then you wont have to remember to enterscl ...manually.