.sh file returned file path instead of file name

Thangaraj J

I am writing a .sh file to print the file names one by one. I have installed ubuntu in windows 10 and using the windows command prompt for executing below code. It is returning "E:/Official/Backups/GGG/*" instead of file names inside. I have also changed the EOL conversion to Unix(LF) by using notepad ++. please help.

#!/bin/bash
folder="E:/Official/Backups/GGG"
for entry in "$folder"/*
do
echo "$entry"
done

Running the script outputs:

$ bash test1.sh
E:/Official/Backups/GGG/*

Output of echo $-

himBHs

Output of ls -ld E:/Official/Backups/GGG

ls: cannot access 'E:/Official/Backups/GGG': No such file or directory
Socowi

My bash in WSL does not recognize windows paths. If I want to access E:\Official\Backups\GGG I would have to use /mnt/e/Official/Backups/GGG.

I assume, the same goes for your WSL bash. Therefore the "path" E:/Official/Backups/GGG is just a non-existing directory and your observed behavior is to be expected. With bash's default settings a * just stays there as a literal if the directory does not exist or is empty. Example:

$ echo /dir/that/doesnt/exist/*
/dir/that/doesnt/exist/*
$ echo /dir/that/exists/but/is/empty/*
/dir/that/exists/but/is/empty/*
$ echo /dir/*
/dir/file1 /dir/file2 /dir/file3 ...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related