Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awk: 1: unexpected character '\' #2

Closed
fawdlstty opened this issue Nov 6, 2020 · 6 comments
Closed

awk: 1: unexpected character '\' #2

fawdlstty opened this issue Nov 6, 2020 · 6 comments

Comments

@fawdlstty
Copy link

环境 win10 2004 (19041.610),wsl2,系统自带bash
执行后报错:

awk: 1: unexpected character '\'
awk: 1: unexpected character '\'
The Script Exited, the ip address of WSL 2 cannot be found

测试后发现awk语法可能有点问题,bash测试执行结果:

fa@FAWDLSTTY-PC:/mnt/c/Users/fawdlstty$ ip route
default via 172.24.48.1 dev eth0
172.24.48.0/20 dev eth0 proto kernel scope link src 172.24.61.238
fa@FAWDLSTTY-PC:/mnt/c/Users/fawdlstty$ ip route | grep default
default via 172.24.48.1 dev eth0
fa@FAWDLSTTY-PC:/mnt/c/Users/fawdlstty$ ip route | grep default | awk '{print \`$3}'
awk: 1: unexpected character '\'
@bytemain
Copy link
Owner

bytemain commented Nov 6, 2020

你说的应该是 wsl2.ps1 这个文件里的,因为 powershell 脚本在执行的时候会转义 $ 这个字符 所以 `$ 可以让 $ 不被转义。

在 bash 中直接执行 ip route | grep default | awk '{print $3}' 即可

@fawdlstty
Copy link
Author

直接执行脚本也需要这么改呀,,,

@bytemain
Copy link
Owner

bytemain commented Nov 6, 2020

哈哈 我这里是通过 pwsh 里调用 bash.exe -c {语句}

所以要让这里的 {语句} 里的内容都转义正确

@fawdlstty
Copy link
Author

貌似我又发现一个神奇的问题,wsl.local在宿主只能ping通,这功能我是想着转发kubernetes dashboard,然后:

fa@FAWDLSTTY-PC:/mnt/c/Users/fawdlstty$ minikube dashboard
🤔  Verifying dashboard health ...
🚀  Launching proxy ...
🤔  Verifying proxy health ...
🎉  Opening http://127.0.0.1:43909/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
👉  http://127.0.0.1:43909/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

我将这个地址换成wsl.local访问不了,ip也不行,但wsl2内能访问。是否还缺一个设置?

@bytemain
Copy link
Owner

bytemain commented Nov 6, 2020

wsl2 能访问是因为它会向主机查询 dns(因为 nameserver 指向了 windows 主机),主机会把 hosts 中的域名直接缓存起来然后直接作为一个 dns 记录。

docker 可能不走这个设置,可能需要手动设置一下 dns 的地址为主机(我没试过)....

@fawdlstty
Copy link
Author

谢谢,我再看看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants