-2

I am trying to execute a command with multiple parameters in a bash script:

#!/bin/bash
read a[{1..3}] <<< $(echo /opt/CPshrd-R77/bin/cpview history off); echo "${a[1]} ${a[2]} ${a[3]}"
#"/opt/CPshrd-R77/bin/cpview history off"

for (( i =0 ; i < ${#a[@]} ; i++ ))
do
        printf "\n Running '$(a[$1]}' \n\n"
        eval "${a[$i]}"
done

I hacked together this script from a couple examples on stackoverflow. What is happening is the cpview utility is being called instead of the full command terminating the history. Cpview is a Check Point utility used to display CPU, Memory, network stats, firewall performance, etc. Its buggy and it has a memory leak, so I need to shut it off.

  • 1
    Why do you need all this script for running `/opt/CPshrd-R77/bin/cpview history off` command? – anubhava Jul 27 '16 at 22:18
  • 1
    ...there's a lot that's wrong in here, but it almost doesn't seem worth tearing it down piece-by-piece; the answers to those issues generally fall into the category of "don't do that". – Charles Duffy Jul 27 '16 at 22:27
  • (I mean, that in the world is the possible use of `read a[{1..3}] <<< $(echo /opt/CPshrd-R77/bin/cpview history off)`? I can't conceive of a scenario where it would be more correct than `read -a a <<<"/opt/CPshrd-R77/bin/cpview history off"`, even if you *did* want to read each word in a command into a separate array element... but there's also no obvious reason why you need an array at all. And evaluating each word in that array as if it were a separate command? Why would that ever be useful?) – Charles Duffy Jul 27 '16 at 22:29
  • ...I mean, seriously, why *isn't* your script just one line after the shebang, that line being `/opt/CPshrd-R77/bin/cpview history off`? – Charles Duffy Jul 27 '16 at 22:30

1 Answers1

-1

Turns out that this was caused by the cpview binary. I worked around the issue by running a bash script to kill the process.