1

I come here because I have an error that I don't understand.

I have a file named "test.css" which contain:

body {
    /* Petit test de commentaire */
    background: url("/dev/null");
    border : 2px white solid ;
} 

/**
 *  Commentaire
 * sur ********
 * plusieurs //
 * lignes !!!
 */
body:hover {
    color: red!important;
}

When I do

cat test.css

, nothing wrong.

But if I do

echo `cat test.css`

or

echo $(cat test.css)

I have :

body { /bin /boot /cdrom /dev /etc /home /initrd.img /initrd.img.old /lib /lib32 /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /snap /srv /sys /tmp /usr /var /vmlinuz /vmlinuz.old Petit test de commentaire new/ testComment/ testdir/ background: url("/dev/null"); border : 2px white solid ; } /bin /boot /cdrom /dev /etc /home /initrd.img /initrd.img.old /lib /lib32 /lib64 /lost+found /media /mnt /opt /proc /root /run /sbin /snap /srv /sys /tmp /usr /var /vmlinuz /vmlinuz.old block.txt log.txt mini.sh new newFile.css test2.html test3.html test4.html testComment testdir test.html tr Commentaire block.txt log.txt mini.sh new newFile.css test2.html test3.html test4.html testComment testdir test.html tr sur block.txt log.txt mini.sh new newFile.css test2.html test3.html test4.html testComment testdir test.html tr block.txt log.txt mini.sh new newFile.css test2.html test3.html test4.html testComment testdir test.html tr plusieurs // block.txt log.txt mini.sh new newFile.css test2.html test3.html test4.html testComment testdir test.html tr lignes !!! new/ testComment/ testdir/ body:hover { color: red!important; }

My goal is use the command tr but for that i use cat test.css | tr '\n' ' '

So, if you can help me to fix this issue, thanks!

( I work with (k)Ubuntu 17.04 )

1 Answers1

0

The asterisk * is interpreted by the shell, and expanded to your reachable path.

To avoid that behaviour, use quotes to enclose the results:

echo "$(<test.css)"

To store in a var:

$ VAR="$(<test.css)"

$ echo "$VAR"
body {
    /* Petit test de commentaire */
    background: url("/dev/null");
    border : 2px white solid ;
} 

/**
 *  Commentaire
 * sur ********
 * plusieurs //
 * lignes !!!
 */
body:hover {
    color: red!important;
}

From bashman page:

Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, \, and , when history expansion is enabled, !. The characters $ and ` retain their special meaning within double quotes.

Juan Diego Godoy Robles
  • 14,447
  • 2
  • 38
  • 52