Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
bash: exec prog $var quoting issue... [wrong]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3660

PostPosted: Mon Aug 21, 2023 4:39 pm    Post subject: bash: exec prog $var quoting issue... [wrong] Reply with quote

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
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 21849

PostPosted: Mon Aug 21, 2023 4:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3660

PostPosted: Mon Aug 21, 2023 5:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 21849

PostPosted: Mon Aug 21, 2023 6:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3660

PostPosted: Mon Aug 21, 2023 9:10 pm    Post subject: Reply with quote

EDIT: Hu, you're right. Silly me :oops:
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
View user's profile Send private message
sabayonino
Veteran
Veteran


Joined: 03 Jan 2012
Posts: 1019

PostPosted: Tue Aug 22, 2023 1:01 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum