shell 开头
#!/bin/bash
#/bin/bash<
文件权限
$ ll total 4-rw-r--r-- 1 root root 88 Apr 24 22:15 demo.sh
- 其中可以看到,demo.sh没有可执行权限;但是 bash demo.sh可以运行
$ ./demo.sh -bash: ./demo.sh: Permission denied $ bash ./demo.sh shell demo
$ chmod 755 ./demo.sh # or$ chmod u+x ./demo.sh # 给当前拥有者添加可执行权限$ ll -rwxr--r-- 1 root root 88 Apr 24 22:15 demo.sh
shell 输出 - echo
$ echo -e "helloworld" $ echo -e "helloworld" $ echo -e "hellofworld"
# e[35m开启,e[0m关闭 $ echo -e "e[35moke[0m" $ echo -e "e[32mOKe[0m"
shell - 输出 printf
$ printf "%5d" 12 # 十进制右对齐输出,但是默认不换行$ printf "%-5d" 12 # 十进制左对齐输出
shell - 输入 read
$ read name #把输入的值,赋值给name$ echo $name $ read name age address # 读入3组$ echo $name $age $address$ read -p "请输入用户名" user$ echo $user$ read -t -10 -p "请输入用户名" user # 3s后自动退出等待输入状态$ echo $user$ read -s -p "请输入密码" pass # 不显示方式输入密码
shell - 管道|
* who查看最近登录用户 * wc 统计输入数据的行数-l,单词数 -w, 字节-c,字符-m $ who | wc -l * ss 可查看系统服务监听的端口,grep 具备过滤功能 $ ss -nutlp | grep sshd