linux - 如何将此代码转换为 shell 脚本?

标签 linux bash shell ubuntu

关闭。这个问题需要更多 focused .它目前不接受答案。












想改进这个问题?更新问题,使其仅关注一个问题 editing this post .


1年前关闭。







Improve this question




我正在尝试将以下代码从批处理文件转换为 Shell 脚本。
我很难过,感觉比整理一个批处理文件要复杂得多。
任何帮助将不胜感激:
下面的代码:

@echo off
    echo %PATH%
    

@for /f "delims=[] tokens=2" %%a in ('ping -n 1 google.com') do (
    set "Google_IP=%%a"
)

pause

@for /f "delims=[] tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^|
findstr [') do (
    set "MY_IP=%%a"
)


)


echo Google IP : %Google_IP%
netstat -a
tracert google.com
echo IP of Current Computer : %MY_IP%


pause>nul & exit

最佳答案

丑陋的方式

#!/bin/bash

echo "Google IP : $(host -t A google.com | cut -d ' ' -f 4)"
netstat -a
traceroute google.com
echo "IP of Current Computer : $(getent hosts $(hostname -s) | cut -d ' ' -f 1)"
我会去
#!/bin/bash

host -t A google.com
#netstat -a
#traceroute google.com
getent hosts $(hostname -s)

关于linux - 如何将此代码转换为 shell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62822318/

相关文章:

linux - 如何获取我从 shell 脚本执行的命令列表的 PID

bash - bash中变量的while循环

macos - 在 Swift 中运行 Shell 命令

python - 无法将python变量传递给hive -e

linux - 如何使用 shell 脚本根据数字名称值删除目录?

c - 使用套接字传输文件服务器/客户端 linux C

java - 系统 loadLibrary 在多线程中使用时挂起

c - 可以执行二进制文件的代码示例

linux - 如何使用 %F bash shell 检测文件内容中的日期

linux - 验证输入的最后 4 个字符的 Bash 脚本