shell fuction
函数定义
xxx.sh1 2 3
| function funcName() { }
|
xxx.sh1 2 3 4
| f2() { value=$(($1+$2+1)) echo $1 "+" $2 "=" $value }
|
传参
xxx.sh1 2 3 4
| function funcName() { echo $1 echo $2 }
|
调用
xxx.sh1 2 3 4 5
| function funcName() { echo $1 echo $2 } funcName 刘喵喵 大帅哥
|
shell1 2
| . xxx.sh funcName 刘喵喵 大帅哥
|
如果function写在/etc/profile
、~/.bashrc
下,则可以直接调用
应用
- 有了以上方法,在bashrc中将自己常用但容易遗忘的命令写成函数,就可以方便的调用了
- 如果函数忘了,,那就可以去
~/.bashrc
下看看😅x1
- 如果忘记去哪里看了,,,那就来看看这篇文章😅x2
- 如果忘记这篇文章,,,那我直接😅x3
~/.bashrc1 2 3 4 5 6 7 8
| function setgitproxy() { git config --global http.proxy 'socks5h://localhost:7890' git config --global https.proxy 'socks5h://localhost:7890' } function unsetgitproxy() { git config --global --unset http.proxy git config --global --unset https.proxy }
|
ubuntu中创建unit
systemctl
systemctl 提供了一组子命令来管理单个的 unit,其命令格式为:
1
| systemctl [command] [unit]
|
创建unit
1
| sudo vim /etc/systemd/system/xxx.service
|
xxx.service1 2 3 4 5 6 7 8 9 10 11
| [Unit] Description=clash daemon
[Service] Type=simple User=root ExecStart=/opt/xxx/xxx -d /etc/xxx/ Restart=on-failure
[Install] WantedBy=multi-user.target
|
1
| sudo systemctl daemon-reload
|
1
| sudo systemctl start xxx.service
|
1
| sudo systemctl enable xxx.service
|