Hello, I would like to know why
cmd = “/bin/df -H /dev/#{partition}”
used = #{cmd}
works fine but this fails
used = "/bin/df -H /dev/#{partition}"
with an OS error.
Thank you
BTW, is there an aliase to the backquote ? I mean a kernel method doing
the same - Just for the syntax, backquotes are not very sexy.
Zouplaz wrote:
BTW, is there an aliase to the backquote ? I mean a kernel method doing
the same - Just for the syntax, backquotes are not very sexy.
You don’t need the quotes when you surround the command with backquotes.
Use this instead:
used = /bin/df -H /dev/#{partition}
When you use both quotes and backquotes, the quotes are treated as part
of the command. That’s what causes the error.
You can use %x instead of backquotes:
used = %x(/bin/df -H /dev/#{partition})
Zouplaz wrote:
Hello, I would like to know why
cmd = “/bin/df -H /dev/#{partition}”
used = #{cmd}
works fine but this fails
used = "/bin/df -H /dev/#{partition}"
with an OS error.
Well, first of all they aren’t equivalent. For instance, writing this:
str = “hello”
puts “Hi, #{str} world.”
isn’t equivalent to writing:
puts “Hi, “hello” world.”
I don’t know enough about Unix to know the reason for the system error,
but this works:
flags = “-l”
puts ls #{flags}
But, this does not:
puts "ls -l"
The internal quotes messes things up.
BTW, is there an aliase to the backquote ? I mean a kernel method doing
the same - Just for the syntax, backquotes are not very sexy.
puts %x{ls -l}
On Oct 13, 8:28 pm, Zouplaz [email protected] wrote:
BTW, is there an aliase to the backquote ? I mean a kernel method doing
the same - Just for the syntax, backquotes are not very sexy.
I think the syntax is great, but you can also use the following:
puts Kernel::`(“ls”)
Still uses a backquote, but it’s more like a traditional method call.
Or as described on p. 351 of the pickaxe, you can alias the backquote:
alias :cmd :`
puts cmd “ls”
This worked for me when running a program, but not from irb.
But if you give it some time, I think you may like the simplicity of:
result = ls
le 14/10/2007 05:21, Gerardo S. Gómez Garrido nous a dit:
“/bin/df -H /dev/wd0a”
and the shell cannot find the program named “/bin/df -H /dev/wd0a”
Thanks for the hint (and others posters too) !
2007/10/13, Zouplaz [email protected]:
Hello, I would like to know why
cmd = “/bin/df -H /dev/#{partition}”
used = #{cmd}
works fine but this fails
used = "/bin/df -H /dev/#{partition}"
with an OS error.
Let partition be “wd0a”.
In the first case, you’re executing:
/bin/df -H /dev/wd0a
which the shell interprets correctly as a call the program /bin/df
with the specified options and parameters.
In the second case you’re executing:
“/bin/df -H /dev/wd0a”
and the shell cannot find the program named “/bin/df -H /dev/wd0a”