Sample Header Ad - 728x90

Shell expension in variable allocation containing the char '*'

0 votes
0 answers
20 views
For the shell fans (bash) : I want a variable to get a value resulting from an operation output which contains an globbing character (such as *), and the shell expansion always happens, even if I quote or doublequote the expression. To reduce the problem scope, all the three following commands return the current directory file list (which is quite strange for me, as I never met this issue before after 30 years of shell practice !!! Still time to learn) :
-bash
var=*; echo ${var}
var="*"; echo ${var}
var='*'; echo ${var}
but I would like the last command to print simply the * character. I've searched thru the shopt options but didn't find any one to solve the issue. Has anyone an idea?
Asked by misterpc (1 rep)
Apr 9, 2025, 01:33 PM
Last activity: Apr 9, 2025, 01:36 PM