BigArmsWriteSmallCode
BigArmsWriteSmallCode

Reputation: 33

I want to get all the filenames into a variable in a particular path

I want to get all the filename into a variable in a path so that I could list all the files inside it no matter what type they are.

As of now If there is a directory inside the file or a folder then its name should be displayed not its content

#!/bin/sh
echo Hello World
for file in /C:/Users/shubham.tomar/Desktop/Shell/Test1/*
do
    echo inside loop
    filename=$(basename "$file")
    echo File -> $filename
done

Output:

Hello World
inside loop
demo.sh: line 8: $filename: ambiguous redirect

Upvotes: 0

Views: 326

Answers (1)

Gereon
Gereon

Reputation: 17844

Replace echo File -> $filename with echo "File -> $filename"

Upvotes: 1

Related Questions