Jump to content

help on quotation


Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 .....

Link to comment
Share on other sites

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:

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...