title: Script to go to every subdirectory of a folder and run command
body: <p>I am trying to write a script that performs the following steps:
  1. Go to every folder in a directory which was given as parameter when running the script.
  2. Make a folder in each subdirectory called "Histogram"
  3. Read out every file with the Ending *.jpg
  4. Convert a picture into a txt-file by the command "Convert XY -format %c histogram:info:XY.txt
  5. Move txt-file to folder "Histogram"
  6. Go back to start directory and continue with next folder</p>
  
  <p>This is what I got so far:</p>
  
  <pre><code>pfad="${1:-.}"
  cd "$pfad/"
  mkdir Histogram
  for i in 'ls -1 *.jpg'
  do
  cat $1 |
  convert $i -format %c histogram:info:"Histogram_$1'.txt"|
  mv "Histogram_$i'.txt" Histogram/
  </code></pre>
  
  <p>It is still missing, that the script executes the command for each subdirectory, also the making of the folder and the moving of the txt-file in the folder does not work.</p>