「EOL」とbashリダイレクトを使用して「cat」を使用してコードスニペットをファイルにピップする方法は?

「EOL」とbashリダイレクトを使用して「cat」を使用してコードスニペットをファイルにピップする方法は?

コードスニペットを$x

しかし、、で構文エラーが発生します<<--

パスワード

cat > "$x" <<-- EOF
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
#auto lo wlan0
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
#iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface $interface inet static
        address 192.168.50.5
        netmask 255.255.255.0
        network 192.168.50.0
        broadcast 192.168.50.255
allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
EOF

ベストアンサー1

cat < "$x" <<-- EOL

構文エラーではないようです。ただ文字列-ここでは、オプションのダッシュのみが必要です。)、その後にEOL一般的な引数が続きますcat。つまり、 と関連がある。

cat EOL < "$x" <<--

これは次のとおりです。

cat EOL <<--

入力を2回リダイレクトするからですcat。後者は効果がありますが、ファイル名も提供されているため、ここでは読もうとしませcatん。stdin

私の考えでは、あなたが望むもの

cat > "$x" <<-EOF
    blah
EOF

おすすめ記事