Freebsd

如何在 csh 的內置 echo 命令中正確使用 excape 字元?

  • May 10, 2012

我正在嘗試在安裝過程中使用腳本建構我的 fstab,所以我想要這樣的東西:

printf '# Device\t\tMountpoint\tFSType\tOptions\t\tDump\tPass#' >> /mnt/etc/fstab
printf '\n/dev/ada0p4.elia\t/\t\tufs\trw\t\t1\t2' >> /mnt/etc/fstab
printf '\n/dev/ada0p3.eli\t\tnone\t\tswap\tsw\t\t0\t0' >> /mnt/etc/fstab
printf '\n/dev/ada0p2\t\t/unencrypted\tufs\tro\t\t1\t1' >> /mnt/etc/fstab

有沒有辦法用echo在csh中做到這一點?

我已經嘗試過,但它無法正常工作。例如,這是我的 FreeBSD 9.0-RELEASE-p1 盒子上的測試和輸出:

# echo test\ttest > test
# cat test
testttest

這裡出了什麼問題?

Csh 的內置 echo 不支持此功能,因此您需要鍵入系統 echo 命令的路徑。此外,您需要添加額外的反斜杠或將反斜杠放在引號中。

這些中的任何一個都應該起作用。

/usr/bin/echo test\\ttest > test

或者

/usr/bin/echo 'test\ttest' > test

與我之前發布的相反,您不需要使用 -e 標誌。這只是 GNU 的 echo 命令需要的。

引用自:https://serverfault.com/questions/387719