我正在尝试将用户的命令行历史记录中的字符串拆分为命令行参数。例如,我想拆分
program argument escaped\ argument.txt -o 'another escaped.output'
Run Code Online (Sandbox Code Playgroud)
进入
$v[1]: program
$v[2]: argument
$v[3]: escaped argument.txt
$v[4]: -o
$v[5]: another escaped.output
Run Code Online (Sandbox Code Playgroud)
我已经尝试了所有可能的解决方案,但是由于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
Run Code Online (Sandbox Code Playgroud)
这滥用了fish的命令行缓冲区,该缓冲区确实正确标记了其内容。