我试图将字符串从用户的命令行历史记录拆分为命令行参数。例如,我想拆分
program argument escaped\ argument.txt -o 'another escaped.output'
进入
$v[1]: program
$v[2]: argument
$v[3]: escaped argument.txt
$v[4]: -o
$v[5]: another escaped.output
我已经尝试了所有可能的解决方案,但是由于fish会自动引用变量,因此我的解决方案均无效。
谢谢!
当前,没有干净的方法可以在鱼类中做到这一点。
我能想到的最好的办法是破解:
set s "program argument escaped\ argument.txt -o 'another escaped.output'"
set oldcmd (commandline)
commandline -r -- $s
set v (commandline -o)
commandline -r -- $oldcmd
printf '%s\n' $v
这滥用了fish的命令行缓冲区,该缓冲区确实正确标记了其内容。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句