Jump to content
Sign in to follow this  
mentosan

help on quotation

Recommended Posts

mentosan

I need to run this command:

"C:\Program Files\Putty\putty.exe" -load "HOME" -ssh -P 22 192.168.1.1

The IP address is declared as variable.

So I'm using this line :

$Cmd = @ComSpec & " /k " & '"' & @ProgramFilesDir & '\Putty\putty.exe" -load "HOME" -ssh -P 22' & $ipadress[1]

I'm confused with quotation. Can you help to have the right command ?

Thank you

Share this post


Link to post
Share on other sites
mentosan

Hello ?!

Any help ,please

Share this post


Link to post
Share on other sites
MHz

Your quotation seems OK but your spacing does not. Use a Msgbox to show the string for debug purposes and you may see the issue.

Global $ipadress[2]
$ipadress[1] = '0.0.0.0'

$Cmd = @ComSpec & " /k " & '"' & @ProgramFilesDir & '\Putty\putty.exe" -load "HOME" -ssh -P 22' & $ipadress[1]
MsgBox(0, 'Test 1', $Cmd)

$Cmd = @ComSpec & " /k " & '"' & @ProgramFilesDir & '\Putty\putty.exe" -load "HOME" -ssh -P 22 ' & $ipadress[1]
MsgBox(0, 'Test 2', $Cmd)

$Cmd = '"' & @ComSpec & '" /k "' & @ProgramFilesDir & '\Putty\putty.exe" -load "HOME" -ssh -P 22 ' & $ipadress[1]
MsgBox(0, 'Test 3', $Cmd)

The 1st Msgbox shows your posted attempt. The 2nd Msgbox show a modified attempt with a space added. The 3rd is how I would quote it using single quotes as default with double quotes as part of the string.

Share this post


Link to post
Share on other sites
mentosan

Thanks for that.

Could you explain how is quotation made in your example ? Single quotation include double-quotation or opposite ?

In Help Manual, I only see explanation about double-quotation wrapped by double-quotation .....

Share this post


Link to post
Share on other sites
MHz

AutoIt gives you flexibility with quoting. You can double up quotes, use single quotes to wrap double quotes or use double quotes to wrap single quotes. The choice is yours as is needed. The usual that I prefer by default is single wrapping double quotes as @Comspec etc like double quotes being passed in the command string. You can alternate quoting to suit the task at hand.

; double quotes wrapping single quotes
$string = "'" & "single quotes" & "'"
MsgBox(0, 'Test 1', $string)

; single quotes wrapping double quotes
$string = '"' & 'double quotes' & '"'
MsgBox(0, 'Test 2', $string)

; single quotes doubling up on themselves
$string = '''' & 'single quotes' & ''''
MsgBox(0, 'Test 3', $string)

; double quotes doubling up on themselves
$string = """" & "double quotes" & """"
MsgBox(0, 'Test 4', $string)

; isn't is an odd string (contains a single quote so use double quotes to wrap it)
$string = "isn't this an odd string with a single quote"
MsgBox(0, 'Test 5', $string)

; as previous but double quoted
$string = '"' & "isn't this an odd string double quoted" & '"'
MsgBox(0, 'Test 6', $string)

; simple use of keeping single quotes
$string = "'single quotes'"
MsgBox(0, 'Test 7', $string)

; simple use of keeping double quotes
$string = '"double quotes"'
MsgBox(0, 'Test 8', $string)

With pleasure :mellow:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.