Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My script looks like this:

PROJECT_DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)

COMMANDS_CODE=$(php $PROJECT_DIR/bin/console generate:code)


The output has all newlines stripped (which doesnt happen if I call the script directly) and contains some strange paths at the beginning like this:

/bin /boot /cdrom /dev /etc /home 
/initrd.img /lib /lib64 /lost+found 
/media /mnt /opt /proc /root /sbin 
/selinux /srv /sys /tmp /usr /var /vmlinuz 
... here starts the actual output but without any newlines ...

(The above is actualy one long string which is echoed I just added some newlines for readability)

What´s happening there?

If I do a

php bin/console generate:code

in my project dir in my bash shell everything works fine.

share|improve this question
Try echo "$COMMANDS_CODE" – Tim Jul 28 '12 at 20:44
@Tim thanks! that worked…… uh… I really know nothing about shell as I just learned again. How come? Care to post an answer so you can have your well deserved reputation? :-) – Max Jul 28 '12 at 20:46
No prob Max, answer added. :) – Tim Jul 28 '12 at 22:46
up vote 5 down vote accepted

Try wrapping the variable in double quotation marks. Example: echo "$COMMANDS_CODE"

You can learn more about shell variables and quotation marks here, under the section "The Importance of Quotation Marks".

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.