From: maksym
To: [email protected]
Subject: globbing and backslash when parameter expansion
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe -fno-plt
-fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security
-fstack-clash-protection -fcf-protection -fno-omit-frame-pointer
-mno-omit-leaf-frame-pointer -g
-ffile-prefix-map=/build/bash/src=/usr/src/debug/bash -flto=auto
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin'
-DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/bash.bashrc'
-DSYS_BASH_LOGOUT='/etc/bash.bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS
-std=gnu17
uname output: Linux inspiron 6.12.28-1-lts #1 SMP PREEMPT_DYNAMIC Fri, 09 May
2025 08:29:37 +0000 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu
Bash Version: 5.2
Patch Level: 37
Release Status: release
Description:
The backslash escape symbol works inconsistently when unquoted parameter
expansion occurs
Repeat-By:
Say, I have a directory named '\*123' (literally: backslash, asterisk,
one, two, three).
For being more clean, set the shell option `shopt -s nullglob`
Following code produces unexpected results:
pat='\*'
echo $pat
It prints '\*' instead of '\*123'. Looks like backslash works as escape
symbol here,
but for asterisk only. If you assign `pat='\\'`, it will print '\\' as
expected. To get expected result,
you need to assign `pat='\\*'`. I think it's confusing.