Skip to main content
deleted 18 characters in body
Source Link
xpt
  • 1.9k
  • 7
  • 28
  • 56

Very similar with Run a command in an interactive shell with ssh after sourcing .bashrc, yet the answer there doesn't work for me.

I want to to execute remote command via ssh under the full interactive shell. I.e.,
run a remote command under the login shell, with some parameters.

Basically, I need the following two cases to work:

ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'
ssh user@remote_computer -t 'bash -l -c "java -version"'

But currently I got a blank line from case 1, and -version: line 1: java: command not found from case 2:

$ ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'

Connection to remote_computer closed.

$ ssh user@remote_computer -t bash -l -c 'true; /bin/echo PATH is $PATH'
PATH is /usr/local/bin:/usr/bin:/bin:/usr/games
Connection to remote_computer closed.

ssh user@remote_computer -t bash -l -c 'true; java -version'
bash: line 1: java: command not found
Connection to remote_computer closed.

UPDATE:

At least two people think it is a quoting problem, but please can any one explain why it is a quoting problem, and how can I get what I wanted above. For e.g., this is also what I had tried:

ssh user@remote_computer -t 'bash -l -c "java -version"'
bash: line 1: java: command not found
Connection to remote_computer closed.

And I've run out of ideas how to quote it in a different way. Please help!

If I run the same command after ssh user@remote_computer, I'll get:

$ bash -l -c "java -version"
openjdk version "11.0.15" 2022-04-19 LTS
OpenJDK Runtime Environment Zulu11.56+19-CA (build 11.0.15+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)

So this is clearly not a quoting problem to me.

Very similar with Run a command in an interactive shell with ssh after sourcing .bashrc, yet the answer there doesn't work for me.

I want to to execute remote command via ssh under the full interactive shell. I.e.,
run a remote command under the login shell, with some parameters.

Basically, I need the following two cases to work:

ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'
ssh user@remote_computer -t 'bash -l -c "java -version"'

But currently I got a blank line from case 1, and -version: line 1: java: command not found from case 2:

$ ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'

Connection to remote_computer closed.

$ ssh user@remote_computer -t bash -l -c 'true; /bin/echo PATH is $PATH'
PATH is /usr/local/bin:/usr/bin:/bin:/usr/games
Connection to remote_computer closed.

ssh user@remote_computer -t bash -l -c 'true; java -version'
bash: line 1: java: command not found
Connection to remote_computer closed.

UPDATE:

At least two people think it is a quoting problem, but please can any one explain why it is a quoting problem, and how can I get what I wanted above. For e.g., this is also what I had tried:

ssh user@remote_computer -t 'bash -l -c "java -version"'
bash: line 1: java: command not found
Connection to remote_computer closed.

And I've run out of ideas how to quote it in a different way. Please help!

If I run the same command after ssh user@remote_computer, I'll get:

$ bash -l -c "java -version"
openjdk version "11.0.15" 2022-04-19 LTS
OpenJDK Runtime Environment Zulu11.56+19-CA (build 11.0.15+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)

So this is clearly not a quoting problem to me.

Very similar with Run a command in an interactive shell with ssh after sourcing .bashrc, yet the answer there doesn't work for me.

I want to to execute remote command via ssh under the full interactive shell. I.e.,
run a remote command under the login shell, with some parameters.

Basically, I need the following two cases to work:

ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'
ssh user@remote_computer -t 'bash -l -c "java -version"'

But currently I got a blank line from case 1, and java: command not found from case 2:

$ ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'

Connection to remote_computer closed.

$ ssh user@remote_computer -t bash -l -c 'true; /bin/echo PATH is $PATH'
PATH is /usr/local/bin:/usr/bin:/bin:/usr/games
Connection to remote_computer closed.

ssh user@remote_computer -t bash -l -c 'true; java -version'
bash: line 1: java: command not found
Connection to remote_computer closed.

UPDATE:

At least two people think it is a quoting problem, but please can any one explain why it is a quoting problem, and how can I get what I wanted above. For e.g., this is also what I had tried:

ssh user@remote_computer -t 'bash -l -c "java -version"'
bash: line 1: java: command not found
Connection to remote_computer closed.

And I've run out of ideas how to quote it in a different way. Please help!

If I run the same command after ssh user@remote_computer, I'll get:

$ bash -l -c "java -version"
openjdk version "11.0.15" 2022-04-19 LTS
OpenJDK Runtime Environment Zulu11.56+19-CA (build 11.0.15+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)

So this is clearly not a quoting problem to me.

added 7 characters in body
Source Link
xpt
  • 1.9k
  • 7
  • 28
  • 56

Very similar with Run a command in an interactive shell with ssh after sourcing .bashrc, yet the answer there doesn't work for me.

I want to to execute remote command via ssh under the full interactive shell. I.e.,
run a remote command under the login shell, with some parameters.

Basically, I need the following two cases to work:

ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'
ssh user@remote_computer -t bash'bash -l -c 'java"java -version'version"'

But currently I got nothinga blank line from case 1, and -version: line 1: java: command not found from case 2:

$ ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'

Connection to remote_computer closed.

$ ssh user@remote_computer -t bash -l -c 'true; /bin/echo PATH is $PATH'
PATH is /usr/local/bin:/usr/bin:/bin:/usr/games
Connection to remote_computer closed.

ssh user@remote_computer -t bash -l -c 'true; java -version'
bash: line 1: java: command not found
Connection to remote_computer closed.

UPDATE:

At least two people think it is a quoting problem, but please can any one explain why it is a quoting problem, and how can I get what I wanted above. For e.g., this is also what I had tried:

ssh user@remote_computer -t 'bash -l -c "java -version"'
bash: line 1: java: command not found
Connection to remote_computer closed.

And I've run out of ideas how to quote it in a different way. Please help!

If I run the same command after ssh user@remote_computer, I'll get:

$ bash -l -c "java -version"
openjdk version "11.0.15" 2022-04-19 LTS
OpenJDK Runtime Environment Zulu11.56+19-CA (build 11.0.15+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)

So this is clearly not a quoting problem to me.

Very similar with Run a command in an interactive shell with ssh after sourcing .bashrc, yet the answer there doesn't work for me.

I want to to execute remote command via ssh under the full interactive shell. I.e.,
run a remote command under the login shell, with some parameters.

Basically, I need the following two cases to work:

ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'
ssh user@remote_computer -t bash -l -c 'java -version'

But currently I got nothing from case 1, and -version: line 1: java: command not found from case 2:

$ ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'

Connection to remote_computer closed.

$ ssh user@remote_computer -t bash -l -c 'true; /bin/echo PATH is $PATH'
PATH is /usr/local/bin:/usr/bin:/bin:/usr/games
Connection to remote_computer closed.

ssh user@remote_computer -t bash -l -c 'true; java -version'
bash: line 1: java: command not found
Connection to remote_computer closed.

UPDATE:

At least two people think it is a quoting problem, but please can any one explain why it is a quoting problem, and how can I get what I wanted above. For e.g., this is also what I had tried:

ssh user@remote_computer -t 'bash -l -c "java -version"'
bash: line 1: java: command not found
Connection to remote_computer closed.

And I've run out of ideas how to quote it in a different way. Please help!

If I run the same command after ssh user@remote_computer, I'll get:

$ bash -l -c "java -version"
openjdk version "11.0.15" 2022-04-19 LTS
OpenJDK Runtime Environment Zulu11.56+19-CA (build 11.0.15+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)

So this is clearly not a quoting problem to me.

Very similar with Run a command in an interactive shell with ssh after sourcing .bashrc, yet the answer there doesn't work for me.

I want to to execute remote command via ssh under the full interactive shell. I.e.,
run a remote command under the login shell, with some parameters.

Basically, I need the following two cases to work:

ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'
ssh user@remote_computer -t 'bash -l -c "java -version"'

But currently I got a blank line from case 1, and -version: line 1: java: command not found from case 2:

$ ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'

Connection to remote_computer closed.

$ ssh user@remote_computer -t bash -l -c 'true; /bin/echo PATH is $PATH'
PATH is /usr/local/bin:/usr/bin:/bin:/usr/games
Connection to remote_computer closed.

ssh user@remote_computer -t bash -l -c 'true; java -version'
bash: line 1: java: command not found
Connection to remote_computer closed.

UPDATE:

At least two people think it is a quoting problem, but please can any one explain why it is a quoting problem, and how can I get what I wanted above. For e.g., this is also what I had tried:

ssh user@remote_computer -t 'bash -l -c "java -version"'
bash: line 1: java: command not found
Connection to remote_computer closed.

And I've run out of ideas how to quote it in a different way. Please help!

If I run the same command after ssh user@remote_computer, I'll get:

$ bash -l -c "java -version"
openjdk version "11.0.15" 2022-04-19 LTS
OpenJDK Runtime Environment Zulu11.56+19-CA (build 11.0.15+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)

So this is clearly not a quoting problem to me.

Post Reopened by Kamil Maciorowski, Stephen Kitt bash
added 357 characters in body
Source Link
xpt
  • 1.9k
  • 7
  • 28
  • 56

Very similar with Run a command in an interactive shell with ssh after sourcing .bashrc, yet the answer there doesn't work for me.

I want to to execute remote command via ssh under the full interactive shell. I.e.,
run a remote command under the login shell, with some parameters.

Basically, I need the following two cases to work:

ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'
ssh user@remote_computer -t bash -l -c 'java -version'

But currently I got nothing from case 1, and -version: line 1: java: command not found from case 2:

$ ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'

Connection to remote_computer closed.

$ ssh user@remote_computer -t bash -l -c 'true; /bin/echo PATH is $PATH'
PATH is /usr/local/bin:/usr/bin:/bin:/usr/games
Connection to remote_computer closed.

ssh user@remote_computer -t bash -l -c 'true; java -version'
bash: line 1: java: command not found
Connection to remote_computer closed.

UPDATE:

At least two people think it is a quoting problem, but please can any one explain why it is a quoting problem, and how can I get what I wanted above. For e.g., this is also what I had tried:

ssh user@remote_computer -t 'bash -l -c "java -version"'
bash: line 1: java: command not found
Connection to remote_computer closed.

And I've run out of ideas how to quote it in a different way. Please help!

If I run the same command after ssh user@remote_computer, I'll get:

$ bash -l -c "java -version"
openjdk version "11.0.15" 2022-04-19 LTS
OpenJDK Runtime Environment Zulu11.56+19-CA (build 11.0.15+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)

So this is clearly not a quoting problem to me.

Very similar with Run a command in an interactive shell with ssh after sourcing .bashrc, yet the answer there doesn't work for me.

I want to to execute remote command via ssh under the full interactive shell. I.e.,
run a remote command under the login shell, with some parameters.

Basically, I need the following two cases to work:

ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'
ssh user@remote_computer -t bash -l -c 'java -version'

But currently I got nothing from case 1, and -version: line 1: java: command not found from case 2:

$ ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'

Connection to remote_computer closed.

$ ssh user@remote_computer -t bash -l -c 'true; /bin/echo PATH is $PATH'
PATH is /usr/local/bin:/usr/bin:/bin:/usr/games
Connection to remote_computer closed.

ssh user@remote_computer -t bash -l -c 'true; java -version'
bash: line 1: java: command not found
Connection to remote_computer closed.

UPDATE:

At least two people think it is a quoting problem, but please can any one explain why it is a quoting problem, and how can I get what I wanted above. For e.g., this is also what I had tried:

ssh user@remote_computer -t 'bash -l -c "java -version"'
bash: line 1: java: command not found
Connection to remote_computer closed.

And I've run out of ideas how to quote it in a different way. Please help!

Very similar with Run a command in an interactive shell with ssh after sourcing .bashrc, yet the answer there doesn't work for me.

I want to to execute remote command via ssh under the full interactive shell. I.e.,
run a remote command under the login shell, with some parameters.

Basically, I need the following two cases to work:

ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'
ssh user@remote_computer -t bash -l -c 'java -version'

But currently I got nothing from case 1, and -version: line 1: java: command not found from case 2:

$ ssh user@remote_computer -t bash -l -c '/bin/echo PATH is $PATH'

Connection to remote_computer closed.

$ ssh user@remote_computer -t bash -l -c 'true; /bin/echo PATH is $PATH'
PATH is /usr/local/bin:/usr/bin:/bin:/usr/games
Connection to remote_computer closed.

ssh user@remote_computer -t bash -l -c 'true; java -version'
bash: line 1: java: command not found
Connection to remote_computer closed.

UPDATE:

At least two people think it is a quoting problem, but please can any one explain why it is a quoting problem, and how can I get what I wanted above. For e.g., this is also what I had tried:

ssh user@remote_computer -t 'bash -l -c "java -version"'
bash: line 1: java: command not found
Connection to remote_computer closed.

And I've run out of ideas how to quote it in a different way. Please help!

If I run the same command after ssh user@remote_computer, I'll get:

$ bash -l -c "java -version"
openjdk version "11.0.15" 2022-04-19 LTS
OpenJDK Runtime Environment Zulu11.56+19-CA (build 11.0.15+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)

So this is clearly not a quoting problem to me.

added 436 characters in body
Added to review
Source Link
xpt
  • 1.9k
  • 7
  • 28
  • 56
Loading
Post Closed as "Duplicate" by Gilles 'SO- stop being evil' bash
edited tags
Link
Gilles 'SO- stop being evil'
  • 866.1k
  • 205
  • 1.8k
  • 2.3k
Loading
added 689 characters in body
Source Link
xpt
  • 1.9k
  • 7
  • 28
  • 56
Loading
Source Link
xpt
  • 1.9k
  • 7
  • 28
  • 56
Loading