2017-03-03 37 views
1

我来这里因为我有一个我不明白的错误。Bash错误CSS文件

我有一个名为 “test.css” 包含文件:

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

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

当我做

cat test.css 

,无可厚非。

但如果我这样做

echo `cat test.css` 

echo $(cat test.css) 

我:

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; } 

我的目标是使用命令tr但是,我使用cat test.css | tr '\n' ' '

所以,如果你能帮我解决这个问题,谢谢!

+1

你不需要这里'cat',google''Useless-Use-Of-Cat',你只需要'echo'$( Inian

+0

\ *'和其他特殊字符正在被你正在运行的shell解释,因此你为什么得到/ * – FreudianSlip

+0

目录的列表啊,是的。我已经看到Useless-Use-Cat,但我不知道用什么来代替。谢谢 –

回答

0

星号*由shell来解释,并扩大到您的到达路径(我与(K)的Ubuntu 17.04的工作)。

为了避免这种行为,使用引号包围结果:

echo "$(<test.css)" 

要存储在一个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; 
} 

bash手册页:

围护字符在双引号保留的 所有字符引号内的字面意义,的$,`,\例外,而且在启用, 历史扩展,!字符$和`保留 它们在双引号内的特殊含义。

+0

谢谢,它的工作!但是,你知道为什么当我不附上结果时,它打印目录的名称? –

+0

如果我想使用一个变化:我该怎么做? 'VAR = $(echo“$(

+0

非常感谢! –