# Mixing string formatting with system exec

**URL:** <https://www.ruby-forum.com/t/mixing-string-formatting-with-system-exec/195608>\
**Category:** Ruby\
**Created:** [September 26, 2010, 9:26pm UTC](https://www.ruby-forum.com/t/mixing-string-formatting-with-system-exec/195608 "2010-09-26T21:26:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![diemorph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/76d3ee/32.png) [@diemorph](https://www.ruby-forum.com/u/diemorph)\
**Post date:** [September 26, 2010, 9:26pm UTC](https://www.ruby-forum.com/t/mixing-string-formatting-with-system-exec/195608/1 "2010-09-26T21:26:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![diemorph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/76d3ee/32.png) [@diemorph](https://www.ruby-forum.com/u/diemorph)\
**Post date:** [September 26, 2010, 10:00pm UTC](https://www.ruby-forum.com/t/mixing-string-formatting-with-system-exec/195608/2 "2010-09-26T22:00:38Z")

</div>

On 26.09.2010 21:26, Nate St.Germain wrote:

> 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

---

<div class="post-metadata">

**Author:** ![diemorph](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/76d3ee/32.png) [@diemorph](https://www.ruby-forum.com/u/diemorph)\
**Post date:** [September 27, 2010, 3:43am UTC](https://www.ruby-forum.com/t/mixing-string-formatting-with-system-exec/195608/3 "2010-09-27T03:43:30Z")

</div>

Robert K. wrote:

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

ahh, got it. thanks, robert.
