View previous topic :: View next topic |
Author |
Message |
CaptainBlood Advocate
Joined: 24 Jan 2010 Posts: 3660
|
Posted: Mon Aug 21, 2023 4:39 pm Post subject: bash: exec prog $var quoting issue... [wrong] |
|
|
My snippet: Quote: | exec emacs $file_list | My bash editor claims: SC2086: Double quote to prevent globbing and word splitting.
Any idea how to quote to remove reported error?
Thks 4 ur attention, interest & support. _________________ USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Last edited by CaptainBlood on Mon Aug 21, 2023 9:22 pm; edited 2 times in total |
|
Back to top |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 21849
|
Posted: Mon Aug 21, 2023 4:55 pm Post subject: |
|
|
SCnnnn looks like a shellcheck message. A search for your error message leads to https://www.shellcheck.net/wiki/SC2086, which is indeed a shellcheck page. According to that page, you should place double quotes around the variable. |
|
Back to top |
|
|
CaptainBlood Advocate
Joined: 24 Jan 2010 Posts: 3660
|
Posted: Mon Aug 21, 2023 5:09 pm Post subject: |
|
|
Hmm,
Problem is that it doesn't work... Code: | fl="file1 file2";exec emacs $fl | works fine, whereas Code: | fl="file1 file2";exec emacs "$fl" | fails here...
Thks 4 ur attention, interest & support. _________________ USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. " |
|
Back to top |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 21849
|
Posted: Mon Aug 21, 2023 6:04 pm Post subject: |
|
|
Please explain how it does not work. The latter version you showed should silence the shellcheck warning, and open a file named file1 file2. Per the guidance on that page, if you want word splitting, you need to use an array or disable the warning. |
|
Back to top |
|
|
CaptainBlood Advocate
Joined: 24 Jan 2010 Posts: 3660
|
Posted: Mon Aug 21, 2023 9:10 pm Post subject: |
|
|
EDIT: Hu, you're right. Silly me
I've just started to code review for a script, with the reported issue as a final line of code.
Code: | fl="file1 file2";exec emacs $fl | opens 2 buffers named file1 file2 whereas Code: | fl="file1 file2";exec emacs "$fl" | doesn't open any buffer at all. [EDIT] Actually it opens a buffer named "file1 file2", undisplayed at start, which lead me to mistake.
The 1) working case has been in use for years now here, but SpellChecker doesn't like it.
I'm just trying to make things the right way. I'll leave it as it was.
Thks 4 ur attention, interest & support. _________________ USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. " |
|
Back to top |
|
|
sabayonino Veteran
Joined: 03 Jan 2012 Posts: 1019
|
Posted: Tue Aug 22, 2023 1:01 am Post subject: |
|
|
Hi
try this code in your bash script
Code: |
#!/bin/bash
fl="file1 file2"; exec emacs $(echo $fl)
|
or try to expand the "fl" variable (not really need)
Code: |
#!/bin/bash
fl="file1 file2"; exec emacs $(echo ${fl})
|
Cheers _________________ LRS i586 on G.Drive
LRS x86-64 EFI on MEGA |
|
Back to top |
|
|
|