mixing string formatting with system exec

N

Nate St.Germain

noob question…

why does this line produce the following result?

%x("%s %s" % ['/usr/bin/touch', '/tmp/test'])

error:
sh: line 0: fg: no job control

i don't necessarily need to use string formatting or substitution here,
just curious about the result.

thanks.
 
R

Robert Klemme

noob question…

why does this line produce the following result?

%x("%s %s" % ['/usr/bin/touch', '/tmp/test'])

error:
sh: line 0: fg: no job control

i don't necessarily need to use string formatting or substitution here,
just curious about the result.

thanks.

%x is backticks and the contents between brackets are passed unmodified
to the shell:

Robert@babelfish ~
$ ruby19 -e 'p %x[ls a]'
ls: cannot access a: No such file or directory
""

Robert@babelfish ~
$ ruby19 -e 'p %x["ls a"]'
sh: ls a: command not found
""

You are essentially doing the same as this:

irb(main):002:0> system '"%s %s" % [\'/usr/bin/touch\', \'/tmp/test\']'
sh: line 0: fg: no job control
=> false

You get the same if you call bash as sh directly:

Robert@babelfish ~
$ /bin/sh -c '"%s %s"'
/bin/sh: line 0: fg: no job control


Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top