大数据全系列 教程
1869个小节阅读:465.1k
目录
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
java语言中的方法
xxxxxxxxxx
public int methodName(int x,String name){
......
}
javascript函数:
xxxxxxxxxx
function mN(x,name){
......
}
Shell脚本中的函数:
xxxxxxxxxx
myShellName () {
command1
command2
command3
……
}
函数调用:
xxxxxxxxxx
myshellname
案例实战:
xxxxxxxxxx
[root@node1 ch4]# vim fun.sh
#!/bin/bash
# 定义函数
myFunName(){
echo "hello world $1"
}
# 函数调用
myFunName www.bjsxt.com
[root@node1 ch4]# chmod +x fun.sh
[root@node1 ch4]# ./fun.sh
hello world www.bjsxt.com
总结:
当前bash进程中执行脚本:source fileName
xxxxxxxxxx
[root@node1 ch4]# echo $$
14729
[root@node1 ch4]# cat my.sh
#!/bin/bash
ls -l /
echo "hello world"
echo $$
pstree -p
[root@node1 ch4]# source my.sh
总用量 24
lrwxrwxrwx. 1 root root 7 8月 17 01:28 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 8月 17 01:33 boot
....
hello world
14729
systemd(1)─┬─NetworkManager(677)─┬─{NetworkManager}(690)
│ └─{NetworkManager}(692)
|-....
├─sshd(902)─┬─sshd(934)───bash(1033)
│ ├─sshd(1034)───sftp-server(1038)
│ ├─sshd(14726)───bash(14729)───pstree(15815)
子进程执行:bash mysh.sh或者./mysh.sh(需要该文件具有可执行权限)
xxxxxxxxxx
[root@node1 ch4]# ./my.sh
总用量 24
lrwxrwxrwx. 1 root root 7 8月 17 01:28 bin -> usr/bin
......
hello world
15802
systemd(1)─┬─NetworkManager(677)─┬─{NetworkManager}(690)
│ └─{NetworkManager}(692)
├─......
├─sshd(902)─┬─sshd(934)───bash(1033)
│ ├─sshd(1034)───sftp-server(1038)
│ ├─sshd(14726)───bash(14729)───my.sh(15802)───pstree(15804)
8. 定义函数:
xxxxxxxxxx
funName() {
各种命令
}