简体   繁体   中英

Bash script double quote

I have an issue with a bash script and need to ask for some help. The script is following:

#!/bin/bash
config_options="CFLAGS=\"-Wall -pipe\""
./configure --prefix=$PWD/install $config_options

If I use run this script, I got the error "unrecognized option -pipe". However, if I directly use the following command, it works.

./configure --prefix=$PWD/install CFLAGS="-Wall -pipe"

My understanding is that this command and the bash script are exactly the same, since I already put escape character \\ before ". I don't know why this script gave an error.

Please let me know if you need more information.

Thanks!

You cannot pass-in command line options in a string variable like this. You can use BASH array instead:

#!/bin/bash
config_options=(CFLAGS="-Wall -pipe")
./configure --prefix=$PWD/install "${config_options[@]}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM