1

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

3
  • Since the batch isn't valid it is difficult to guess what you have in mind. Commented May 9, 2017 at 22:25
  • It looks like bash that somebody tried to convert to batch Commented May 9, 2017 at 23:14
  • the batch is valid, i've tried it, i just don't know how to convert it to shell Commented May 10, 2017 at 8:24

1 Answer 1

1

Try Using Basename.

In your Case:

for file in "$PATH"/$str_Begin_With*.txt
do
NAME=$(basename "$file")
echo "$NAME"
done
Sign up to request clarification or add additional context in comments.

1 Comment

that's what i was looking for ! Thank's

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.