Bash syntax : double quotes give error in script

Hello.

This command return an error :

sudo cp -v “$MAIN_DATA_PROGRAM_PATH/001_FIREFOX_NATIVE_FIREFOX/ICON_STANDARD/000*” /usr/share/icons/breeze/apps/32/

The error is :

cp: cannot stat ‘/run/media/user_install_vb/NVIDIA_OPTIMUS/000_DATA_PROGRAM/001_FIREFOX_NATIVE_FIREFOX/ICON_STANDARD/000*’: No such file or directory

This one is Ok

sudo cp -v “$MAIN_DATA_PROGRAM_PATH/001_FIREFOX_NATIVE_FIREFOX/ICON_STANDARD”/000* /usr/share/icons/breeze/apps/32/

This one without quote is also OK

sudo cp -v $MAIN_DATA_PROGRAM_PATH/001_FIREFOX_NATIVE_FIREFOX/ICON_STANDARD/000* /usr/share/icons/breeze/apps/32/

What is the rule ?

Thank you for helping

First and for all: you should ALWAYS use the Preformatted text feature and NOT the Quote feature of the forums when posting computer code (is this really new to you?). Now all your " characters are fouled up into “ and ” (which are of course not the same)!

Then you have somewhere 000* in that string. According to man bash

Quoting is used to remove the special meaning of certain characters or words to the shell. Quoting can be used to disable special treatment for special characters, …

and

Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, ,

The * is such a special character. Thus inside the quotes it will loose it’s special meaning for path extention.

Now I am extremely confused. You have been posting questions about elaborate shell scripts for years and only now you are asking the very basic question about how shell works? Amazing …

Quotes by definition prevent globbing so your program gets the literal string. Second and third examples are identical as long as the value of your variable does not contain spaces.

Sorry but I may not be a guru in all aspect of bash ( and fore sure in many other domains )

Thank you every body

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.