Krishna Chikkala
Krishna Chikkala

Reputation: 91

bash not able to execute command in a variable

cdm="home/nmsadm/tngVersion/iconTestNetworkGenerator.sh -input /home/nmsadm/ipr/ipr_files/IP_1.xml -templateDir /home/nmsadm/Try_K/1 -nocs -erbsstart 1 -subnetwork 25 -iprstart 11"

#above statment is in a single line

$cdm

I stored one command in a variable called cdm, now I want to run this command so I used $cdm. But I'm getting an error

home/nmsadm/tngVersion/iconTestNetworkGenerator.sh: No such file or directory

I'm pretty sure that there is file in that specified directory.

How should I fix this?

Upvotes: 0

Views: 93

Answers (2)

Jens
Jens

Reputation: 72629

Since you specified the name of a command along with a directory the command is supposed to be in, there is no PATH lookup performed. Apparently you are not in a directory where the pathname

  home/nmsadm/tngVersion/iconTestNetworkGenerator.sh

refers to an existing file. Fix this either by using an absolute path, probably

  /home/nmsadm/tngVersion/iconTestNetworkGenerator.sh

or by cd'ing to the proper directory first, probably

  cd /
  $cmd

Upvotes: 2

Jan Hudec
Jan Hudec

Reputation: 76236

It is apparently trying to execute the command. The error quotes the command name from the variable. But the command is wrong. Did you by any chance forget initial /?

Upvotes: 5

Related Questions