-1
N = hostname
echo $N //Output: ABC123
echo $N | tr [:upper:] [:lower:] //Output: abc123
N = $(echo $N | tr [:upper:] [:lower:]) //Output: Command not found

I can modify the hostname using tr and send it to the terminal, but I can't put it back into a variable. Why?

  • too much spaces : `N=$(...)` would likely work; isn't the exact error message `-bash: N : command not found` ? `N = something` is parsed as `launch the 'N' command with parameters '=' and 'something'`. – Aaron Dec 03 '18 at 15:46
  • 2
    I also suggest to use [shellcheck](https://www.shellcheck.net/) to lint your scripts, it would have caught this error. – Aaron Dec 03 '18 at 15:51

1 Answers1

1

There's two extra spaces surrounding the assignment operator (=).

N=$(echo $N | tr [:upper:] [:lower:])

The command above will work.

dbakiu
  • 238
  • 4
  • 8