0
Command="tr ' ' '\n' < /location/to/file.xml | sed -e '/\/Name/, $d' | grep Apple | wc -l"
New_command=`$Command`

The error I am getting:

tr: extra operand \'\\n\'' Trytr --help' for more information.

What is wrong with what I am doing? Trying to assign a string variable to 'New_Command' so I can execute it and get the output.

Jens
  • 67,715
  • 15
  • 98
  • 113
Noodlelynx
  • 15
  • 1
  • 8
  • 4
    Don't use strings to store code, use functions. – Tom Fenech May 09 '17 at 08:17
  • Not recommended: `eval "$command"` – Cyrus May 09 '17 at 08:20
  • I tested there is no **error** for me. `bash 4.3` – Shakiba Moshiri May 09 '17 at 08:29
  • You should probably also be using an XML parser. In any case, it would be helpful to know exactly what you're trying to do (sample input + desired output) rather than trying to guess from your attempt. – Tom Fenech May 09 '17 at 08:31
  • the following command shows how arguments are splitted: `printf "'%s'\n" $Command` this is due to different phases in command processing. Also the pipe '|' will be interpreted as a character instead of pipe. the error message means: tr accept only two arguments first is "'" and second is "'" – Nahuel Fouilleul May 09 '17 at 09:17

0 Answers0