0

I have simple question but it's annoying me .. who don't know ,js-beautify is a library to make ugly stinky js files more readable and beauty ,hence the name ;D

when I do $ js-beautify somefile.js in bash ,every thing is good and the output is clean as expicted ,but when I try to store that output in a variable readable=$(js-beautify somefile.js) then echo $readable ,nothing changed !! like I didn't use js-beautify at all !!

what's the problem here ?

at_Root
  • 71
  • 5
  • Also: Is the command being found? Is it in the $PATH? – B. Shea Jun 17 '22 at 22:51
  • @B.Shea sorry for the delay (time difference) ... yes the command being found, I installed it via python `pip install js-beautify` and it works fine ,but when i store it in bash variable then `echo` it ,it still ugly **not beautified** – at_Root Jun 18 '22 at 14:12
  • Now that I understand the question, I took a look. Answer is below :-) – B. Shea Jun 19 '22 at 00:21

1 Answers1

1

Echo the variable with double quotes:

echo "$readable"

That should give you proper EOLs/newlines. (Also see BASH "Double Quotes").

Please note that many blocks of code may not 'expand'/prettify. To test command line output in shell versus online, run it in BASH shell and check it against results here: https://beautifier.io

(It's the same version my pip installed for python/bash use.)

Also see:

Capturing multiple line output into a Bash variable


PS (to your comment above on question):
To properly install the Python3 pip version, the command is actually:
pip3 install jsbeautifier (Or, 'pip'. But, not js-beautify - that's the shell command.)

B. Shea
  • 829
  • 14
  • 29
  • 1
    sheeeeesh thank you so much it works <3 ,how I didn't think about that ! but while that time I sharped my bash skills a bit and did a nasty stuff just to solve it ,and it works also – at_Root Jun 19 '22 at 02:39