The script below should open an entry box whose initial entry-text is the value of $filename, but the zenity section in the third line ignores that variable and I end up with no entry-text.
By the way, if I just replace filename by whoami, my username will appear as expected. I’m not able to get a result using my own variables, though. That’s the problem.
#!/bin/bash
filename="duck"
sh -c 'chromium-browser "https://duckduckgo.com/?q=%5C$(zenity --entry --text "I am feeling ducky" --entry-text $(filename))"'
And if I removed the sh -c stuff, to end up with the code below, my variable would work with zenity.
#!/bin/bash
filename="duck"
zenity --entry --text "I am feeling ducky" --entry-text $filename
Any clues as to why? I tried playing with different combination of quotes but my efforts were futile.
The notation
$(filename)runs a command ‘filename’.To expand a variable, use
${filename}.Note, too, that unless
$filenameis an exported variable, the sub-shell (the one that runs the-coption) will not see the value of the variable (because of the single quotes).To fix that, you’d have to use double quotes – rather carefully: