0

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?

Tim
  • 14,999
  • 1
  • 45
  • 68
Yuxuan
  • 71
  • 7

2 Answers2

1

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?

fork0
  • 3,401
  • 23
  • 23
0

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.

Alan Curry
  • 14,255
  • 3
  • 32
  • 33
  • It did ran, the machine 192.168.1.23 can receive the file. – Yuxuan Jul 02 '12 at 03:34
  • All right then, you must have had `$command` set already, or you're using a shell (which one?) that doesn't behave like any I've seen. Or you really have a semicolon in there that you didn't mention. In an case, what output are you expecting? – Alan Curry Jul 02 '12 at 04:12