- 1 year ago
How to pass a single quote (') into a batch script?
Comment
1 / 1
In a batch script, to pass a single quote ('
) as an argument or a value, you need to handle it as a special character. Batch scripts use the caret character (^
) to escape special characters, including the single quote.
Here's how you can pass a single quote as an argument to a batch script:
Example: my_script.bat
batch@echo off
echo Argument 1: %1
To pass a single quote as an argument, you would use the caret character to escape it like this:
batchmy_script.bat ^'
The output will be:
vbnetArgument 1: '
If you need to use a single quote within a string in the batch script itself, you also need to escape it with a caret:
Example: my_script.bat
batch@echo off
set myString=This is a single quote: ^'
echo %myString%
The output will be:
vbnetThis is a single quote: '
By using the caret (^
) as an escape character, you can pass or use a single quote within your batch script without encountering syntax errors or issues.