Reputation: 71
I have a script like this?
command='scp xxx 192.168.1.23:/tmp'
su - nobody -c "$command"
The main shell didn't print any info. How can I get output from the sub command?
Upvotes: 0
Views: 1280
Reputation: 3461
You can get all of its output by just redirecting the corresponding output channel:
command='scp ... '
su - nobody -c "$command" > file
or
var=$(su - nobody -c "$command")
But if you don't see anything, maybe the diagnostics output of scp is disabled? Is there a "-q" option somewhere in your real command?
Upvotes: 1
Reputation: 14711
You aren't actually running the scp. When you use the
VAR=value cmd ...
syntax, the VAR=value
setting goes into the environment of cmd
but it's not available in the current shell. The command after your -c
is empty, or the previous value of $command
if there was one.
Upvotes: 0