0

I have this script shell and i want to execute it in windows:

#!/bin/sh
# Create the structure of folders that will contain the result files
export perl_git_dir=path1
export OUTPUT_DIR=path2
mkdir $OUTPUT_DIR/output_perl

for FILE in `ls *.sh`
 do
    echo  "file is:"$FILE
    if [ -f "$FILE" ];then
        name=${FILE%.*}
        mkdir -p $OUTPUT_DIR/output_perl/"$name"
    fi;     
done

for entry in `ls *.sh`
 do
    if [ -f "$entry" ];then
        echo "enty is "$entry 
        echo "$entry" >> stdout.txt
        echo "$entry" >> stderr.txt
        ./$entry >> stdout.txt 2>> stderr.txt
    fi;     
done

the result that I have is: the creation of the direcory then this repetitive error in "stderr.txt" file

mkdir: cannot create directory ‘path1/output_perl’: File exists
4
  • You should probably add the whole output of your script, not just the error. Why do you use for FILE in `ls *.sh`; do instead of file globbing, i.e. for FILE in *.sh; do? Commented Feb 27, 2019 at 10:39
  • This does not appear to be a DOS/Windows batch-file... Commented Feb 27, 2019 at 10:41
  • Updated tags, as I can't see any Perl code. Commented Feb 27, 2019 at 10:45
  • It is also not clear why the script generates ${OUTPUT_DIR}/output_perl/${basename}. It seems unused, e.g. the scripts are not executed in its directory. Commented Feb 27, 2019 at 10:49

1 Answer 1

1

Code seems to do what it is supposed to do. In my example I replaced .sh with .pl as I don't have any script files lying around. NOTE: the execution errors are expected.

I can only assume that the question is too incomplete to be answered...

#!/bin/sh
_output_dir=path2

for f in *.pl; do
    basename=${f%.*}
    mkdir -p ${_output_dir}/output_perl/${basename}
    echo ${f} >>stdout.txt
    echo ${f} >>stderr.txt
    ./${f} >>stdout.txt 2>>stderr.txt
done

exit 0

Test run:

$ sh dummy.sh 

$ cat stdout.txt 
dummy2.pl
dummy.pl
standard.pl
$ cat stderr.txt 
dummy2.pl
dummy.sh: line 9: ./dummy2.pl: Permission denied
dummy.pl
dummy.sh: line 9: ./dummy.pl: Permission denied
standard.pl
dummy.sh: line 9: ./standard.pl: Permission denied

$ ls path2/output_perl/
dummy  dummy2  standard
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for responding, i just put the script in the adequate path and it works

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.