0

I have a variable:

rules=L002,L003

This rules variable denotes the files to copy from /usr/lib/vera++/scrpts/rules directory. The extension for the files is .tcl.

I am doing something like:

cp -r /usr/lib/vera++/scripts/rules/{${rules}}.tcl .

What goes wrong is that ${rules} is treated completely as a string. But bash should translate that into:

cp -r /usr/lib/vera++/scripts/rules/{L002,L003}.tcl .
Ankit Koirala
  • 354
  • 3
  • 13
  • This is only a duplicate, if `rules` contains integer sequences. I am not sure, if `L002`,`L003` can be counted as an integer sequence. – ceving Apr 01 '19 at 14:07

1 Answers1

1

The easiest way to take an argument and make a command from this argument is to use eval command. In your case whole script will look like:

#!/bin/bash

rules=L002,L003
eval "cp -r /usr/lib/vera++/scripts/rules/{${rules}}.tcl ."
Szczerba
  • 271
  • 1
  • 8