[過去ログ] シェルスクリプト総合 その26 [無断転載禁止]©2ch.net (1002レス)
前次1-
抽出解除 レス栞

このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
リロード規制です。10分ほどで解除するので、他のブラウザへ避難してください。
877
(1): 名無しさん@お腹いっぱい。 [sage] 2018/04/18(水) 23:47:33 AAS
echo "1 + 2" | bc > /tmp/a
とすると/tmp/aには2バイト、16進数で
33 0a のデータが入っています。

a=$(echo "1 + 2" | bc)
printf "$a" > /tmp/a
しかしこうすると$aには1バイトしか入ってないようです。

また [ "$(printf '1')" = "$(printf "1\n\n\n\n\n")" ]
これは一致した文字とみなされるようです

こういった挙動はどこを見れば理解できるでしょうか?
879: 名無しさん@お腹いっぱい。 [] 2018/04/19(木) 00:06:08 AAS
>>877
コマンド置換 $(...) の仕様

外部リンク[html]:pubs.opengroup.org
> removing sequences of one or more <newline> characters at the end of
> the substitution. Embedded <newline> characters before the end of
> the output shall not be removed; however, they may be treated as
> field delimiters and eliminated during field splitting, depending on
> the value of IFS and quoting that is in effect. If the output
> contains any null bytes, the behavior is unspecified.

bashのマニュアルにも同様の記述がある

外部リンク[html]:linuxjm.osdn.jp
> bash は command を実行し、 command の標準出力でコマンド置換の部分を
> 置き換えます。この際、末尾の改行文字は削除されます。 文字列の途中に
> ある改行文字は削除されませんが、 単語分割の際に削除されることがあり
> ます。
前次1-
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル

ぬこの手 ぬこTOP 0.032s