Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7506805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:21:20+00:00 2026-05-29T22:21:20+00:00

x=a=b `echo $x` echo $a I expect the second line to generate a=b, and

  • 0
x="a=b"
`echo $x`
echo $a

I expect the second line to generate “a=b”, and execute it in the context of the main shell, resulting in a new variable a with value b.
However, what I really get (if I enter the commands manually) is the error message after the second line, bash: a=b: command not found

Why is that so?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:21:22+00:00Added an answer on May 29, 2026 at 10:21 pm

    It’s because of the order in which bash parses the command line. It looks for variable definitions (e.g. a=b) before performing variable and command substitution (e.g. commands in backticks). Because of this, by the time echo $x is replaced by a=b, it’s too late for bash to see this as a variable definition and it’s parsed as a command instead. The same thing would’ve happened if you’d just used $x as the command (instead of echo in backticks). As in @mvds’s answer, the eval command can be used to force the command to be reparsed from the beginning, meaning that it’ll be recognized as a variable definition:

    $ x="a=b"
    $ `echo $x`
    -bash: a=b: command not found
    $ $(echo $x)  # Exact same thing, but with cleaner syntax
    -bash: a=b: command not found
    $ $x  # This also does the same thing, but without some extra steps
    -bash: a=b: command not found
    $ eval "$x"  # This will actually work
    $ echo $a
    b
    $ a=  # Start over
    $ eval "$(echo "$x")"  # Another way of doing the same thing, with extra steps
    $ echo $a
    b
    

    Note that when using eval I’ve put all of the references to $x in double-quotes — this is to prevent the later phases of bash parsing (e.g. word splitting) from happening twice, since bash will finish its regular parsing process, then recognize the eval command, and then redo the entire parsing process again. It’s really easy to get unexpected results from using eval, and this removes at least some of the potential for trouble.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

echo date(W,strtotime('2010-01-01')); This outputs 53. I would expect it to output 1. Can anyone
Please explain to me why the very last echo statement is blank? I expect
echo $_POST[name]; //returns the value a user typed into the name field I would
echo date(w,strtotime(date(Y-m-d))); echo date(w,strtotime(date(Y年m月d日))); Save it as utf8.You'll see the second is bigger than
I am sending the echo to mail function via PHP from variable that includes
I've never really used MS server or anything like that before, i have, however
As per example below, I would expect the ouput to be test value, why
let $PWD = /Unix_Volume/Users/a/b/c/d I would expect: echo $PWD | perl -ne 'if( /(\w+)[^\/]/
it's amzing when i send a null value in date() as a second parameter
When I type echo $0 I see - I expect to see bash or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.