I am trying to read comma separated variable in shell script and splitting it like as below
while [ -z "$variable" ]
do printf 'variable: '
read -r variable
[ -z "$variable" ] && echo 'Action number cannot be empty; try again.'
done
for i in $(echo ${variable} | sed "s/,/ /g")
do
echo "$i"
done
It gives be output as below
abc
def
But if i am trying same thing with SSH its not working i am trying as below
while [ -z "$variable" ]
do printf 'variable: '
read -r variable
[ -z "$variable" ] && echo 'Action number cannot be empty; try again.'
done
ssh -i my.pem -p 2022 ec2-user@ip-address 'bash -s' << EOF
sudo su - << SUEOF
echo "input $variable"
for i in $(echo ${variable} | sed "s/,/ /g")
do
echo "$i"
done
SUEOF
EOF
But in SSH its not printing the values of input variable i am using echo to check the variable is passing into SSH session and i can see the variable is passing to SSH session
variable: abc,def
input abc,def
Please help me solving the issue
^(upvoting) and tick-mark (accepting) the answer. Judging from your questions history, you have not accepted answers to any of your previous questionsssh, parse them and then use them?sshconnection, as inssh -i ... ./myscript.sh?