Assuming I want to run commnand stored inside the variable with nullglob turned on. For example:shopt -s nullgloba=echo [foo]bar${a}This gives me an empty output due to the nullglob option of course, but I want the following output (which I am not able to get):[foo]barI tried escaping [] with \ but that just gives me:\[foo\]barWhat is the correct way of escaping it?EDIT (clarification with some context):I have a script like this:shopt -s nullglobfor file in tmp/*.pdb; do    base=$(basename ${file} .pdb)    a=command --option [${base}]foo    ${a}doneshopt -u nullglobWhat I wanted to achieve is to run command for each file with an option which has [] as ordinary characters (without any matching). The nullglob here was used just for the for loop.That is if tmp contains a.pdb run:command --option '[a]foo'and nothing if no such file is present.In a meantime I figured out that moving shopt -u nullglob as the first command in the for loop seems to solve the problem. However, I am curious if I can somehow escape the [] even with nullglob.
Cannot run command inside bash variable including square brackets with nullglob
bash;environment variables;quoting;wildcards
First, read I'm trying to put a command in a variable, but the complex cases always fail!.Then, define a function:a () {    echo [foo]bar}For your script, there is no reason to put the command in a variable first anway; just run the command.shopt -s nullglobfor file in tmp/*.pdb; do    base=$(basename ${file} .pdb)    command --option [${base}]foodoneshopt -u nullglobIf you must store something in variables, separate the command from its options, and use an array to hold the options.shopt -s nullglobcmd=commandfor file in tmp/*.pdb; do    base=$(basename ${file} .pdb)    options=( --option [${base}]foo )    $cmd ${options[@]}doneshopt -u nullglob