Search code examples
bashvariablesambiguous

bash cat a file from a another server to a variable


i am trying to do a basic command of cat to a variable and it does not work..

 lines="not working"
 sshpass -p triltest ssh root@ILCFS 'cat /var/try/check ' > $lines
 echo $lines 


./script.sh: line 34: $lines: ambiguous redirect
not working

the file exists. can anyone help me please?


Solution

  • Use `command` or $(command). I.e.

    lines=$(sshpass -p triltest ssh root@ILCFS 'cat /var/try/check ')
    echo "$lines"