Send string to stdin

前端 未结 6 1669
北海茫月
北海茫月 2020-11-27 09:48

Is there a way to effectively do this in bash:

/my/bash/script < echo \'This string will be sent to stdin.\'

I\'m aware that I could pip

6条回答
  •  暖寄归人
    2020-11-27 10:13

    You were close

    /my/bash/script <<< 'This string will be sent to stdin.'
    

    For multiline input, here-docs are suited:

    /my/bash/script <

    Edit To the comments:

    To achieve binary input, say

    xxd -r -p <

    If you substitute cat for /my/bash/script (or indeed drop the last pipe), this prints:

    私はちんぷんかんぷんな話にナンセンスを翻訳することができ
    

    Or, if you wanted something a little more geeky:

    0000000: 0000 0000 bef9 0e3c 59f8 8e3c 0a71 d63c  ........2=:^V=..z=
    0000020: 7bdc 8e3d 2aaf a03d b67e b23d c74a c43d  {..=*..=.~.=.J.=
    0000030: 0513 d63d 16d7 e73d a296 f93d a8a8 053e  ...=...=...=...>
    0000040: 6583 0e3e 5a5b 173e 5b30 203e 3d02 293e  e..>Z[.>[0 >=.)>
    0000050: d4d0 313e f39b 3a3e 6f63 433e 1c27 4c3e  ..1>..:>ocC>.'L>
    0000060: cde6 543e 59a2 5d3e 9259 663e 4d0c 6f3e  ..T>Y.]>.Yf>M.o>
    0000070: 60ba 773e cf31 803e ee83 843e 78d3 883e  `.w>.1.>...>x..>
    0000080: 5720 8d3e 766a 913e beb1 953e 1cf6 993e  W .>vj.>...>...>
    0000090: 7a37 9e3e c275 a23e dfb0 a63e bce8 aa3e  z7.>.u.>...>...>
    00000a0: 441d af3e 624e b33e 017c b73e 0ca6 bb3e  D..>bN.>.|.>...>
    00000b0: 6fcc bf3e 15ef c33e e90d c83e d728 cc3e  o..>...>...>.(.>
    00000c0: c93f d03e ac52 d43e 6c61 d83e f36b dc3e  .?.>.R.>la.>.k.>
    00000d0: 2f72 e03e 0a74 e43e 7171 e83e 506a ec3e  /r.>.t.>qq.>Pj.>
    00000e0: 945e f03e 274e f43e f738 f83e f11e fc3e  .^.>'N.>.8.>...>
    00000f0: 0000 003f 09ee 013f 89d9 033f 77c2 053f  ...?...?...?w..?
    0000100: caa8 073f 788c 093f 776d 0b3f be4b 0d3f  ...?x..?wm.?.K.?
    0000110: 4427 0f3f 0000 113f e8d5 123f f3a8 143f  D'.?...?...?...?
    0000120: 1879 163f 4e46 183f 8d10 1a3f cad7 1b3f  .y.?NF.?...?...?
    0000130: fe9b 1d3f 1f5d 1f3f 241b 213f 06d6 223f  ...?.].?$.!?.."?
    0000140: bb8d 243f 3a42 263f 7cf3 273f 78a1 293f  ..$?:B&?|.'?x.)?
    0000150: 254c 2b3f 7bf3 2c3f 7297 2e3f 0138 303f  %L+?{.,?r..?.80?
    0000160: 22d5 313f ca6e 333f                      ".1?.n3?
    

    Which is the sines of the first 90 degrees in 4byte binary floats

提交回复
热议问题