Anna
Anna

Reputation: 1627

Converting a Batch script to Shell

I'm trying to convert a Batch script to a shell. The script collect the name of the file that start with a certain String, and simply log it.

here is my batch Script :

PATH = E:/DATA
str_Begin_With = Employee
set FILE_NAME= for %%x in (%PATH%/%str_Begin_With%*.txt) do set FILE_NAME=%%~x
ECHO %FILE_NAME%

This is my Shell attempt:

export FILE_NAME=
for x in [$PATH/$str_Begin_With*.txt]; 
do FILE_NAME= x

Can someone explain to me how does it work on shell, i'm not familiar with it

Upvotes: 1

Views: 626

Answers (1)

Steeve
Steeve

Reputation: 276

Try Using Basename.

In your Case:

for file in "$PATH"/$str_Begin_With*.txt
do
NAME=$(basename "$file")
echo "$NAME"
done

Upvotes: 1

Related Questions