Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My script looks like this:

#!/bin/sh
PROJECT_DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)

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

echo $COMMANDS_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
1  
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
add comment

1 Answer

up vote 4 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
add comment

Your Answer

 
discard

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.