-1

My code is meant to find a /jar folder , loop through the .jar files and create .xml and .trigger files with the same file name. Additionally, it creates an ~ID~ filename ~ID~ field within the XML file.

I am getting the error

mkdir: cannot create directory '': No such file or directory

I have the /tmp folder set up, including an /xml /jar and /trigger folder, so those not being there isn't the issue.

#!/bin/bash

jar_dir= /c/Users/hi/Desktop/Work/tmp/jar
xml_dir= /c/Users/hi/Desktop/Work/tmp/xml
trigger_dir= /c/Users/hi/Desktop/Work/tmp/trigger       

# the following creates output directories if they don't exist

mkdir -p "${xml_dir}"
mkdir -p "${trigger_dir}"

# we start the for loop through all the files named `*.jar` located in the $jar_dir directory
for f in $(find ${jar_dir} -name "*.jar")
do
        file_id=$(basename -s .jar ${f})   # extract the first part of the file name, excluding .jar
       
      
        echo "<ID>${file_id}</ID>" > ${xml_dir}/${file_id}.xml
        touch ${trigger_dir}/${file_id}.trigger   # this one just creates an empty file at ${trigger_dir}/${file_id}.trigger
done
wjandrea
  • 28,235
  • 9
  • 60
  • 81
Ooka
  • 49
  • 2
  • 6
  • 4
    Don't put spaces around the `=` in an assignment. [Shellcheck.net](https://www.shellcheck.net) will point this out, along with several other problems in your code. BTW, you really should be getting error messages from those `var= ` lines, that should tip you off that something's wrong there. – Gordon Davisson Feb 19 '21 at 22:22
  • Does this answer your question? [Command not found error in Bash variable assignment](https://stackoverflow.com/questions/2268104/command-not-found-error-in-bash-variable-assignment) – ilkkachu Feb 19 '21 at 22:25

2 Answers2

1

This command:

jar_dir= /c/Users/hi/Desktop/Work/tmp/jar

is exactly equivalent to

jar_dir="" /c/Users/hi/Desktop/Work/tmp/jar

and tells the shell to run the command /c/Users/hi/Desktop/Work/tmp/jar with the environment variable jar_dir set to the empty string (only for the duration of that command). If /c/.../jar is a directory, that should give you an error, too.

To assign the /c/.../jar string to the variable instead, lose the space.

The error message you get comes from mkdir trying to create a directory with an empty name. (It's a bit confusing though.)

For problems with shell scripts, it often helps to paste the script to https://www.shellcheck.net/, which recognizes most of the usual mistakes and can tell what to do.

See these posts on SO and unix.SE for discussion:

ilkkachu
  • 6,221
  • 16
  • 30
0

xml_dir= /c/Users/hi/Desktop/Work/tmp/xml Can't have a space after the equal. So xml_dir=/c/Users/hi/Desktop/Work/tmp/xml

Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73