脚本功能

  • 命令行参数指定ip连接/获取ifconfig中的本地ip连接
  • 修改.bashrc
#!/bin/bash

net_dev="wifi0" #默认的设备名
FALSE="0"
TRUE="1" # 若无参数则选择本地ipv4 通过正则匹配ifconfig $net_dev的内容
l_ip=$(ifconfig $net_dev | grep "inet" | grep -v "inet6" |
sed 's/^.*inet//g' | sed 's/netmask.*$//g' | sed 's/ //g')
ok_ip=$l_ip
is_ok=$FALSE m_ip=$1 #命令行指定参数获取
if [ "$m_ip" = "" ];then
is_ip=$(echo $l_ip | grep -P "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}")
if [ "$is_ip" = "" ];then
echo "ip is wrong or not found"
else
echo "use local ip"
is_ok=$TRUE
fi
else
is_ip=$(echo $m_ip | grep -P "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}")
if [ "$is_ip" = "" ];then
echo "inputed ip is wrong ,you can retry or using default ip"
else
echo "use inputed ip"
is_ok=$TRUE
ok_ip=$is_ip
fi
fi if [ "$is_ok" = "1" ];then
echo "Waiting for xfce connected to $ok_ip open"
sed -i "$ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/$ok_ip/" ./.bashrc
source ./.bashrc
startxfce4
fi

注意事项

  • 脚本修改的是.bashrc最后一行中的ip
export DISPLAY=192.168.x.x:0
  • 因为脚本中有source命令,所以在终端中执行命令时要加source
# 本地ipv4执行
source ./openxfce4.sh # 指定ip执行
source ./openxfce4.sh ip_addr
  • 执行脚本前先启动xfce4

补充

  • 因为想学习linux内核驱动,又不想放弃子系统,所以把wsl1升到wsl2了,然后悲剧了,没wifi0

The network interface you see in WSL isn't the host machine's network interface directly; what WSL sees is a virtual network interface (for the light VM WSL2 runs within) connected to a Hyper-V virtual switch behind the host's network card, so all WSL's network tools see is that virtual interface, as eth0.

  • 本来以为脚本改下设备名就行,可是没用,目前限于技术水平,只能在windows环境下ipconfig获取WLANIP,然后脚本执行时加上就行。

最新文章

  1. Windows消息机制详解
  2. P6 EPPM Manual Installation Guide (Oracle Database)
  3. node的实践(项目一)
  4. Stakeholder Risk Management
  5. Java核心技术II读书笔记(一)
  6. bzoj 1761: [Baltic2009]beetle 区间dp
  7. 生产者与消费者(二)---await与 signal
  8. 重新开始学习javase_一切都是对象
  9. Android 手机上安装并运行 Ubuntu 12.04(转,没实测)
  10. 阿里云Centos7使用yum安装MySQL5.6的正确姿势
  11. shell基础——字符串处理(转载)
  12. AOP面试遇到的问题
  13. springBoot actuator监控配置及使用
  14. 紧急求助!配置SMTP插件出错,SMTP connect() failed
  15. MySql-5.7.17-20解压缩版安装配置
  16. transform: translate(-50%, -50%) 实现块元素百分比下居中
  17. 2.请介绍一下List和ArrayList的区别,ArrayList和HashSet区别
  18. TensorFlow Training 优化函数
  19. libxml2_ZC积累
  20. jsp中的隐含9对象

热门文章

  1. C#移除字符串中的不可见Unicode字符
  2. centos7连接WIFI
  3. immutable.js学习笔记(二)----- List
  4. 12月21日内容总结——forms组件渲染标签、展示信息、校验数据的一些补充,forms组件参数和源码剖析,modelform组件,Django中间件
  5. 树莓派4B—LCD触摸屏和硬件串口配置
  6. IOS12 + Xscode12 报错:Building for iOS Simulator, but linking in dylib built for iOS, file '/Users/XXX/Desktop/XXXX/XXX.framework/JSSDK' for architecture arm64
  7. esp32 开发资料
  8. vue3和vue2的区别
  9. linux下删除文件夹的软链接时注意千万不能在后面加反斜杠,千万不要用强制删除,否则下面2种场景,你会把源文件删除,要闯祸的
  10. 【雅礼联考DAY02】Magic