1

I set in cmd variable the find syntax: , I use ksh shell/bash

 # cmd=" find /usr/cti/conf -name \"*.tgz*\" "
 # echo $cmd
   find /usr/cti/conf/ -name "*.tgz*"

so why when I want to run the cmd as the following I not actually activate the find ...

 # exec $cmd
  appserver1a:/var/tmp/    ROOT #     ( this exit from the shell )

it’s also not works when I run with double brackets

  exec "$cmd"
  ksh:  find /usr/cti/conf/backup -name "*.tgz*" :  not found

what is the resolution for this?

Remark I not want to set the cmd like this ( this is works )

     cmd=`  find /usr/cti/conf/backup -name "*.tgz*"  `

or

      cmd=$( find /usr/cti/conf/backup -name "*.tgz*" )
2
  • What happens if just say: $cmd instead of exec "$cmd" ? Commented Jun 25, 2015 at 8:53
  • 1
    You can try cmd=(find /usr/cti/conf/backup -name "*.tgz*") then execute it as ${cmd[@]}. Commented Jun 25, 2015 at 9:01

2 Answers 2

1

Store your command string in the variable:

cmd="find /usr/cti/conf/backup -name \"*.tgz*\""

Then, evaluate the variable contents:

eval "$cmd"

UPDATE: the safer option, according to alvits and Gordon:

cmd=(find /usr/cti/conf/backup -name "*.tgz*")
${cmd[@]}
Sign up to request clarification or add additional context in comments.

1 Comment

Don't do this -- eval is an open invitation to subtle and incomprehensible bugs. Use an array (See @alvits' comment) instead.
0

Both solutions - the one provided below and the one posted by Eugeniu Rosca - seem to work for me.

cmd="find /usr/cti/conf/backup -name \"*.tgz*\""
exec $cmd

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.