Bash how to feed multiple command line arguments to Xgraph

37 views Asked by At

Using the Xgraph data plotting tool (XGRAPH), I want to plot a bunch of files named test1.csv test2.csv, ...

The command would be

xgraph -columns 1 2 test1.csv -columns 1 2 test2.csv

and so onĀ· Is there any way I can use brace expansion or some other magic to circumvent manually typing the pattern -columns 1 2 file.csv again and again?

2

There are 2 answers

5
J.Peace On BEST ANSWER

I think this function should work for you...

graph-build() {
  # loop through commandline filenames and join together
  for file in "${@}"; do
    cmd_build+=(-columns 1 2 "${file}")
  done
  # run xgraph
  xgraph "${cmd_build[@]}"
}

# Run with the expansion as required.
graph-build file{1..3}.csv

Edit: Syntax updated due to helpful comments highlighting the whitespace issue with filenames in my initial revisions.

0
pjh On

With the specific set of filenames given in the question you can use brace expansion and eval to replace

xgraph -columns 1 2 test1.csv -columns 1 2 test2.csv ... -columns 1 2 test10.csv

with

eval xgraph ' -columns 1 2 test'{1..10}'.csv'