title: Shell script to open random jpegs with ImageMagick
body: <p>I have a large batch of jpegs. I would like to write a shell script that selects 5 images randomly and then, using imageMagick, put them in  a montage and then open this montage file. I would like this process to occur every 10 seconds. </p>
  
  <p>I have tried this script</p>
  
  <pre><code>for f in *.jpg
  do
  shuf -ezn 5 * | xards -0 -n1 | montage *.jpg | display montage.jpg
  done
  </code></pre>
  
  <p>but it is not working </p>
  
  <p>It opens all of the images and gives me the following error message</p>
  
  <pre><code>image.sh 7: image.sh: Xards: not found 
  </code></pre>
  
  <p>the go.sh script is kept in the same folder/directory as the images and now looks like this: </p>
  
  <pre><code>#!/bin/bash 
  
  # Get list of files into array - just once at start
  files=(*.jpg)
  
  # Do forever
  first=0
  while :; do
     # Shuffle array
     files=( $(shuf -e "${files[@]}") )
  
     # Make montage of first 5 images in shuffled array
     magick montage ${files[0]} ${files[1]} ${files[2]} ${files[3]} ${files[4]} montage.jpg
  
     # Start displaying if first pass - leaving "display" running in background updating itself every second
     if [ $first -eq 0 ] ; then
        display -update 1 montage.jpg &amp;
        first=1
     fi
  
     # Snooze 10 and repeat
     sleep 10
  done
  </code></pre>
  
  <p>However that is returning </p>
  
  <pre><code>go.sh: 4: go.sh: Syntax error: "(" unexpected
  </code></pre>
  
  <p>However, when I run</p>
  
  <pre><code>bash go.sh
  
  </code></pre>
  
  <p>ImageMagick opens all images in the folder in one montage and I get the following error </p>
  
  <pre><code>go.sh: line 12: magick: command not found
  </code></pre>