Team,
I would like to enter a value at execution time within the *system* key
world environment.
However, I am having difficulties entering a value within a quoted string.
For example, I can hard code the following and it works fine:
system("start putty.exe -X -ssh -pw mypassword myuserid@myhostname")
But this requires hard coding the password in the script.
I would like to do something like the following:
system("start putty.exe -X -ssh -pw " ARGV[0] " myuserid@myhostname")
Where: ARGV[0] holds the password entered by the invoker of the script.
Is there a way to substitute within a quoted string?
Is there a better way to do this?
Thank you
Victor
Alle lunedì 27 agosto 2007, Victor Reyes ha scritto:
Team,
I would like to enter a value at execution time within the *system* key
world environment.
However, I am having difficulties entering a value within a quoted string.
For example, I can hard code the following and it works fine:
system("start putty.exe -X -ssh -pw mypassword myuserid@myhostname")
But this requires hard coding the password in the script.
I would like to do something like the following:
system("start putty.exe -X -ssh -pw " ARGV[0] " myuserid@myhostname")
Where: ARGV[0] holds the password entered by the invoker of the script.
Is there a way to substitute within a quoted string?
Is there a better way to do this?
Thank you
Victor
You need string interpolation:
system("start putty.exe -X -ssh -pw #{ARGV[0]} myuserid@myhostname")
In a double quoted string (as well as in a regexp or backtick expression) you
can substitute insert the value of any expression by enclosing it in #{}:
a = 2
puts "a is #{a}"
=> a is 2
This doesn't work in single-quoted strings.
puts 'a is #{a}'
=> a is #{a}
I hope this helps
Stefano
system("start putty.exe -X -ssh -pw #{ARGV[0]} myuserid@myhostname")
···
-----Original Message-----
From: Victor Reyes [mailto:victor.reyes@gmail.com]
Sent: Monday, August 27, 2007 1:27 PM
To: ruby-talk ML
Subject: Substitution within system quoted string
Team,
I would like to enter a value at execution time within the
*system* key
world environment.
However, I am having difficulties entering a value within a
quoted string.
For example, I can hard code the following and it works fine:
system("start putty.exe -X -ssh -pw mypassword myuserid@myhostname")
But this requires hard coding the password in the script.
I would like to do something like the following:
system("start putty.exe -X -ssh -pw " ARGV[0] " myuserid@myhostname")
Where: ARGV[0] holds the password entered by the invoker of
the script.
Is there a way to substitute within a quoted string?
Is there a better way to do this?
Thank you
Victor
Hi,
> From: Victor Reyes [mailto:victor.reyes@gmail.com]
> Sent: Monday, August 27, 2007 1:27 PM
> Subject: Substitution within system quoted string
>
> For example, I can hard code the following and it works fine:
>
> system("start putty.exe -X -ssh -pw mypassword myuserid@myhostname")
>
> But this requires hard coding the password in the script.
> I would like to do something like the following:
>
> system("start putty.exe -X -ssh -pw " ARGV[0] " myuserid@myhostname")
>
> Is there a way to substitute within a quoted string?
> Is there a better way to do this?
system("start putty.exe -X -ssh -pw #{ARGV[0]} myuserid@myhostname")
I don't know what Windows does with this command line. On
Linux you may say a simple
$ ps aux | grep ssh
and the whole command line is shown. Some programs like
GnuPG offer the facility to pipe the password to $stdin;
as far as I know BSD Ssh forbids entirely to pass it from
outside.
Maybe host-based authentication is a better solution for
you.
Bertram
···
Am Dienstag, 28. Aug 2007, 05:34:59 +0900 schrieb Felix Windt:
> -----Original Message-----
--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
never trust parameters or their encoding, or you beg for privilege
escalation problems. The given command will perform both shell
expansion (consider a password like "%PATH%") and parameter
separation (consider a password like "pw; rm -rf /*").
It's much wiser to disallow expansion:
system("start","putty.exe","-X","-ssh","-pw",ARGV[0],"myuserid@myhostname")
- Matthias
···
On 27.08.2007 22:34, Felix Windt wrote:
system("start putty.exe -X -ssh -pw #{ARGV[0]} myuserid@myhostname")