0

I want to run below gnuplot command to generate graph from gpl file.

gnuplot gplfile0.gpl 
gnuplot gplfile1.gpl 
gnuplot gplfile2.gpl 
gnuplot gplfile3.gpl 
gnuplot gplfile4.gpl 
gnuplot gplfile5.gpl 
gnuplot gplfile6.gpl 
..
..
..
..

I have a parent gplfile.gpl which help to generate all require gplfile*.gpl with unique content. I don't want to remove or move or delete parent file form given folder.

I have written a bash shell script to run above commands.

run_script.sh :

#!/bin/bash

echo "Generating the images using gnu plot"

date 

shopt -s extglob
rm -rf *.png

for f in *gpl
do
    gnuplot $f
done

I am able to generate output from all gplfile*.gpl file. But I want to exclude parent gplfile.gpl from running .

How I can exclude running parent gplfile.gpl file from the bash shell script.

Is there any command in the bash shell script to exclude the specific file from run.

Toto
  • 89,455
  • 62
  • 89
  • 125
Danny
  • 68
  • 6

3 Answers3

3

Write a better matching glob. For example match the digit:

for f in *[0-9].gpl

or really, just exclude it:

for f in *.gpl; do
   if [[ "$f" == gplfile.gpl ]]; then continue; fi
KamilCuk
  • 120,984
  • 8
  • 59
  • 111
2

Since you have extglob on then.

for file in !(gplfile).gpl; do echo gnuplot "$file"; done
Jetchisel
  • 7,493
  • 2
  • 19
  • 18
0

You can replace the shell globbing with find and loop over that instead. If you need to exclude just a single file, it is as simple as

for f in $(find . -name "*.gpl" ! -name gplfile.gpl); do echo $f; done
./gplfile9.gpl
./gplfile8.gpl
./gplfile0.gpl
./gplfile1.gpl
..
..
./gplfile4.gpl
Chen A.
  • 10,140
  • 3
  • 42
  • 61