cms-sw / cmssw-osenv

Provides wrapper scripts to provide CMSSW env using singularity
0 stars 1 forks source link

Handle quoted args #3

Closed kpedro88 closed 3 years ago

kpedro88 commented 3 years ago

In order to assign $@ to another variable while preserving quoted arguments, it's necessary to assign it as an array. (This comes from https://stackoverflow.com/questions/3811345/how-to-pass-all-arguments-passed-to-my-bash-script-to-a-function-of-mine; I did not figure it out myself...)

Here's the test, which can be run to show how the current version gives the wrong answer (4). The version in this PR gives the right answer (3).

cat << 'EOF' > testArgs.sh
#!/bin/bash
ARGS=("$@")
echo ${#ARGS[@]}
EOF
chmod +x testArgs.sh
./testArgs.sh 1 "2 3" 4
cmssw-env --cmsos cc6 -B $PWD --pwd $PWD -- ./testArgs.sh 1 "2 3" 4

I also removed the sh -c call, which seemed superfluous; if it's not, let me know and I'll put it back.

cmsbuild commented 3 years ago

A new Pull Request was created by @kpedro88 (Kevin Pedro) for branch master.

@cmsbuild, @smuzaffar, @mrodozov, @iarspider can you please review it and eventually sign? Thanks. @silviodonato, @dpiparo, @qliphy you are the release manager for this. cms-bot commands are listed here

smuzaffar commented 3 years ago

thanks @kpedro88 , this looks good