-1

So i have a script called process_files, and when a file type is called, a directory should be created based on what was inputted into the command line. So for example, when process_files JPG is entered, a JPG directory should be created. However, when i try to do this it also creates the other directories that are in my code. This is the code.

 #!/bin/sh


 $jpg mkdir jpg
 $gif mkdir gif
 $docx mkdir docx
 $png mkdir png
Zak
  • 1
  • 2
    This code should never work. First you need to parse command line arguments. Check out this thread https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash – Alejandro Blasco Nov 07 '19 at 12:51

1 Answers1

-1

I don't think that you'll be able to do it in as short a script as that anyway.

Firstly, you need to refer to the arguments that you have passed in a different manner:

https://www.learnshell.org/en/Passing_Arguments_to_the_Script

Then you need to conditionally compare your input arguments to "jpg"/"gif"/"docx"/"png" strings and run a mkdir command if true:

https://linuxize.com/post/how-to-compare-strings-in-bash/

There are probably fancy shortcuts with the likes of awk but if you are just beginning shell scripting then it's probably better to go down the explicit, iterative route and keep things simple and obvious in early scripts.

There are many online resources for learning shell scripting and they can quickly cover most scenarios and answer most questions.

Pandabat
  • 49
  • 1
  • 6