2017-03-03 36 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

非常感謝! –