Unable to pass single quote `'` in bash program parameter
matopeto opened this issue · 1 comments
Swiftbar 2.0.0
Hi, i want to pass single quote as parameter to bash program (with terminal=false
)
In general, I want to make sure that I escape input from (paste/clipbard)board.
I was unable to pass single qoute, (only in some cases i was able to pass double quote)
Here is what i try:
I have simple test PHP script to determine and logs parameters
#!/opt/homebrew/bin/php
<?php
file_put_contents(realpath(__DIR__) . '/.logs.txt', print_r($argv, true) . PHP_EOL , FILE_APPEND | LOCK_EX);
and I have this swiftbar script:
Escaping
---
1. without param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php'
---
2. text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1=text
3. text param single quoted | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1='text text'
4. text param double quoted | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1="text text"
---
5. single quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1=text's
6. single quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1="text's"
7. single quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1="text\'s"
8. single quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1="text\\'s"
---
9. double quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1=text"s
10. double quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1="text"s"
11. double quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1='text"s'
12. double quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1=\'text\"s\'
And results
1. without param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php'
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
)
✅ This is OK - no parameters given, no parameters logged
2. text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1=text
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text
)
✅ This is OK - one parameter is given, same parameter is recieved and logged
3. text param single quoted | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1='text text'
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text text
)
✅ This is OK - one parameter is given, same parameter is recieved and logged
4. text param double quoted | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1="text text"
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text text
)
✅ This is OK - one parameter is given, same parameter is recieved and logged
5. single quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1=text's
Console.app output:
default 19:17:47.213953+0200 SwiftBar Executing script in background...
/Users/matej/Projects/Others/BitBarPlugins/.write.php
error 19:17:47.282829+0200 SwiftBar Failed to execute script in background
/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
/bin/bash: -c: line 1: syntax error: unexpected end of file
❌🤔 my script wasn't callet at all (but this may be excepted behaviour, but see 9. with double quotes it works)
6. single quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1="text's"
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text
)
Console.app output is without parameters, so I can't determine wat was actually called
default 19:18:37.328480+0200 SwiftBar Executing script in background...
/Users/matej/Projects/Others/BitBarPlugins/.write.php
❌ This not OK - only "text" was passed to the program, even when param1 was escaped/surrounded by double quotes
7. single quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1="text\'s"
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text\
)
❌ This not OK - as in previews example, parameter was cut just before single quote
8. single quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1="text\\'s"
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text\\
)
❌ This not OK - as in previews example, parameter was cut just before single quote
9. double quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1=text"s
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text"s
)
✅ This is OK
10. double quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1="text"s"
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text
)
✅ This is OK - i would expect such a behaviour
11. double quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1='text"s'
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text
)
❌ This not OK - only "text" was passed to the program, even when param1 was escaped/surrounded by single quotes
12. double quote in text param | terminal=false bash='/Users/matej/Projects/Others/BitBarPlugins/.write.php' param1=\'text\"s\'
❌🤔 my script wasn't callet at all
is there any way to escape and pass single quote in bash program parameter? Or maybe see some logs what swiftbar parse and call when i click to row?
Compare to xbar where all cases seems to work as I expect:
1.
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
)
2.
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text
)
3.
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text text
)
4.
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text text
)
5.
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text's
)
6.
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text's
)
7.
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text\'s
)
8.
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text\\'s
)
9.
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text"s
)
10.
- no valid syntax
11.
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => text"s
)
12.
Array
(
[0] => /Users/matej/Projects/Others/BitBarPlugins/.write.php
[1] => \'text\"s\'
)