I am writing a shell script to help me running with the react-native project, my script has the following parts:
#some steps to create $calculated_value...
os_type=$1
shift
script="$calculated_value react-native run-$os_type $@"
$script
When I type this command in terminal:
./scripts/run ios --simulator="iPhone 6"
I expect the script should execute the following command at the end:
"$calculated_value" react-native run-ios --simulator="iPhone 6"
However, the scripts now execute this command:
"$calculated_value" react-native run-ios --simulator=iPhone 6
which the double quotes have disappeared, and terminal just read the simulator without the "6".
I have tried replacing the $@
with $(for i;do echo ${i@Q};done;)
but it gives me the error: line 25: ${i@Q}: bad substitution
I know I can add \
before the double quotes to escape it
but just want to see if there are any solutions I can do to skip adding \
.
---------------------------------------------- EDIT INFO ----------------------------------------------
Now I am using eval
inside the script in order to run the command with a file location.
Inside the scripts, it contains the below steps:
...some calculation to get $envfile
os_type=$1
shift
run_script="ENVFILE=$envfile react-native run-$os_type $@"
eval $run_script
Inside my package.json
:
{
"scripts": {
"dev": "./scripts/dev"
}
}
In my real case, when I type:
npm run dev ios -- --simulator="iPhone 6"
What I expected is:
ENVFILE=env/tw.dev react-native run-ios --simulator="iPhone 6"
But now the command miss the double dash argument.