1

I am writing a bash script which compute a command and execute it.

The result is put in a variable and displayed.

After that, an exec is done.

The program of the exec must accept input data.

In a use case, the input data is not displayed.

I don't understand why...

I found a solution (t2.sh) but I am interessed by the reason why t1.sh does not work as I want.

$ 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
$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.