"exec"コマンドの動作

コマンドを計算して実行するためのbashスクリプトを作成しています。

結果を変数に入れて表示します。

これでexecが完了します。

Execプログラムは入力データを受け入れる必要があります。

ユースケースでは、入力データは表示されません。

なぜか理解できません...

私は解決策(t2.sh)を見つけましたが、なぜt1.shが好きなように機能しないのか疑問に思います。

$ cat t1.sh
#!/bin/bash

t=$\'ssh xxx@localhost "mysql -P3306 -u uuuu -ppppp -h localhost DB_test -e \\\'select now()\\\'"\'

v=$(eval $t | tail -n1)
#v=$(bash <<< $t | tail -n1)

echo $v

exec cat
$ ./t1.sh <<< "toto"
Pseudo-terminal will not be allocated because stdin is not a terminal.
mysql: [Warning] Using a password on the command line interface can be insecure.
2020-04-24 21:56:59
$ ##### toto is not displayed, why ?
$ cat t2.sh
#!/bin/bash

t=$\'ssh xxx@localhost "mysql -P3306 -u uuuu -ppppp -h localhost DB_test -e \\\'select now()\\\'"\'

#v=$(eval $t | tail -n1)
v=$(bash <<< $t | tail -n1)

echo $v

exec cat
$ ./t2.sh <<< "toto"
Pseudo-terminal will not be allocated because stdin is not a terminal.
mysql: [Warning] Using a password on the command line interface can be insecure.
2020-04-24 21:57:10
toto
$

ベストアンサー1

おすすめ記事