Why do I get an error when commands stored in the variable is being executed?

Solution Verified - Updated -

Issue

  • Why do I get an error when commands stored in the variable are being executed?

[example.sh]

#!/bin/sh

CMDSTR=$* 
$CMDSTR

exit 0

Example Output:

# ./example.sh "( cd /tmp ; pwd ; ls -la )"
./example.sh: line 4: (: command not found

Environment

  • Red Hat Enterprise Linux All
  • Shell

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content