Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asterisk glob expansion (*) unexpected behaviour in bash on WSL's 9P mounts #12227

Closed
1 of 2 tasks
daubmannus opened this issue Nov 1, 2024 · 3 comments
Closed
1 of 2 tasks

Comments

@daubmannus
Copy link

daubmannus commented Nov 1, 2024

Windows Version

Microsoft Windows [Version 10.0.19045.5011]

WSL Version

2.3.24.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.153.1-2

Distro Version

Ubuntu 22.04.5

Other Software

No response

Repro Steps

The behavior described in the report is observed only on WSL's 9P mounts of Windows disks.

sudo mkdir -p /mnt/c/test
cd /mnt/c/test
touch 1 2

run the script

#!/bin/bash

# save true file number
true_f_num=$(for fn in *; do echo; done | wc -l)

while :; do
    # count of iterations to outer loop pipe
    echo
    
    # save current file list in file
    echo -n '' >.list
    
    for fn in *; do
        echo "$fn" >>.list
    
    # line below causes unexpected behaviour
    # on 9P mounts (like /mnt/c/...)
    # (WSL2, ubuntu 22.04)
    done | cat > .tmp; rm .tmp
    
    # check 
    [ $(cat .list | wc -l ) -ne $true_f_num ] && break

done | wc -l

output: some random number

cat .list

output:

1
2
2
  • by default, pathname expansion omits files whose names start with . unless the . is explicitly matched by the pattern. Therefore, in the above code, .tmp is not expected to appear in the expansion of *, regardless of the relative timing of its creation.

  • in the example command, pathname expansion is expected to be performed, once, before any iterations of the loop body are performed.

  • it is not expected for pathname expansion to yield duplicate pathnames, because that is not consistent with the Bash or POSIX specifications.

The appearance of duplicate lines in .list indicates that at least one of the previous two expectations is violated. This would be a bug.

see the discussion here:
https://stackoverflow.com/a/79146114/10244657

Expected Behavior

Script runs forever.
File .list is populated with an exact list of files on each iteration of the loop.

Actual Behavior

On WSL's 9P mounts of Windows' disks script stops after some random number of iterations, outputs this number.
File .list contains the name of one of the files in the current directory twice.

Diagnostic Logs

WslLogs-2024-11-01_06-25-00.zip

Copy link

github-actions bot commented Nov 1, 2024

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'.
Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs

Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The script will output the path of the log file once done.

If this is a networking issue, please use collect-networking-logs.ps1, following the instructions here

Once completed please upload the output files to this Github issue.

Click here for more info on logging
If you choose to email these logs instead of attaching to the bug, please send them to [email protected] with the number of the github issue in the subject, and in the message a link to your comment in the github issue and reply with '/emailed-logs'.

Copy link

github-actions bot commented Nov 1, 2024

Diagnostic information
Issue was edited and new log file was found: https://github.com/user-attachments/files/17595981/WslLogs-2024-11-01_06-25-00.zip
Detected appx version: 2.3.24.0

Copy link
Contributor

This issue has been automatically closed since it has not had any author activity for the past 7 days. If you're still experiencing this issue please re-file it as a new issue.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant