Zerg12
Zerg12

Reputation: 317

How to use select statement result as a variable and pass it further to the script

please advise how to use select statement result as a variable and pass it further to the script. Simple script:

#!/bin/sh
# --mysql part START--
pwd="pass"
D="db"
mysql -uuser -p$pwd -D$D  -s -N -e "SELECT port FROM table where username='$1';"
/usr/bin/mysql -uroot -p$pwd -D$D<< eof
eof

port=$(mysql Select) # declaring select result as a variable , probably wrong 
echo "port              $port;" >> /tmp/blabla.txt # <- this part is not working 

Please advise. Thanks in advance

Upvotes: 0

Views: 120

Answers (1)

Domenico Luciani
Domenico Luciani

Reputation: 381

You can put it into an a variable, follow this example:

#!/bin/sh
# --mysql part START--
pwd="pass"
D="db"
user="user"
port=$(mysql -u $user -p $pwd -D $D -s -N -e "SELECT port FROM table where username='$1';")

echo "PORT: $port" > /tmp/blabla.txt

Upvotes: 2

Related Questions