How to use bash $(awk) in single ssh-command?

后端 未结 6 570
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 21:18

I am trying to execute a single command over ssh that contains `sub-code` or $(sub-code) (I use it all the time but I don\'t know the official name for that) to

6条回答
  •  旧时难觅i
    2020-12-02 21:39

    The workaround is to create an sh file with the command then pass it to ssh command:

    test.sh

    echo `uname -a | awk '{print $2}'`
    

    and command:

    ssh myServer 'bash -s' < test.sh
    

    UPDATE:

    The command without quotes works fine as well:

    ssh myServer uname -a | awk '{print $2}'
    

提交回复
热议问题