Applescript: Appropriately escape input in script invocation

applescriptitermkeyboardterminal

I have the following snippet in an applescript:

          tell current session of current tab of current window
              write text "watch -n1 'kubectl get pods | grep -i"  & input'
              split horizontally with default profile
              split vertically with default profile
          end tell

But this does not work given that I am getting the following error:

script error: Expected end of line but found unknown token. (-2741)

I want the end result, given that I will be invoking the script as

myscript appname

To be

watch -n1 'kubectl get pods | grep -i appname'

Any suggestions?

edit: I have also tried this without success:

write text "watch -n1 "\kubectl get pods | grep -i & input\""

Best Answer

Here is what worked for me:

assuming that you grab input by having as a first line in your script the following:

on run {input}

Then you can perform within an iTerm window:

write text "watch -n1 " & "'"  & "kubectl get pods | grep -i " & input & "'"