1

In the bash shell, I'm trying to read the json file and load to a variable

eri@xyz:~/Documents/inbound>e1=$(eval echo $(cat ./deploy/request.json))

Upon fetching the output of that variable, I'm seeing -bash - command not found along with the actual contents of the .json file

eri@xyz:~/Documents/inbound>"$e1"

-bash: { type:Pipeline, category:Software, risk:4, short_description:sample short description text, description:sample detailed description text, assignment_group: Services - Retail Services, cmdb_ci:Retail Service, u_version:1.0, start_date:2017-01-04 18:00:00, end_date:2017-01-04 19:00:00, backout_plan:see department for standard backout plan, implementation_plan:sample implementation plan, test_plan:sample text plan, production_system:false }: command not found

Is there a way to suppress the -bash - command not found in the output?.

1
  • Welcome to the site! Check out the tour and the how-to-ask page for more about asking questions that will attract quality answers. You can edit your question to include more information. Commented Aug 10, 2018 at 2:03

1 Answer 1

1

No need for eval - just e1=$(< ./deploy/request.json) should do the trick. (Thanks to @shellter for the syntax — you don't even need to use cat!)

To show the variable, you want

echo "$e1"

instead of just "$e1". "$e1" by itself on the command line does not print out the value of $e1, unlike many programming-language REPLs. Instead, it tells bash to try to interpret the entire contents of $e1 as the name of a command. It isn't the name of a command, so bash tells you a command by that name cannot be found.

Sign up to request clarification or add additional context in comments.

3 Comments

and you can skip the unneeded cat process by using el=$(< file) . Good luck to all.
@shellter Thanks! I was wondering if this were a uuoc, but didn't know that syntax.
its the same idea as anyProg < file, but somehow the $( cmd_substitution) knows how to do it. Note that just doing < file on the cmd line doesn't produce any output (in my one test just now ;-) ). Glad to share what I know. Good luck to all!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.