栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux Bash Tutorial

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux Bash Tutorial

Main References

Quick Intro:

https://linuxconfig.org/bash-scripting-tutorial-for-beginners

Reference by Modules:

Bash Introduction | What is Bash? - Javatpoint

Unix / Linux - Special Variables

Common Functionalities

Text, Especially Filename and Dirpath Manipulation:

linux通配符和正则表达式_韩帅平的博客-CSDN博客_linux正则表达式

linux shell 中 %% *的含义_lhc_执笔画江山的博客-CSDN博客_shell%%

linux 获取文件名的后缀,Linux shell 之 提取文件名和目录名的一些方法_何政达的博客-CSDN博客

Linux shell string 操作_wangjicong_215的博客-CSDN博客_linux shell string

File Manipulation

Linux Bash脚本检查文件/文件夹是否存在_yaoxinghuo的专栏-CSDN博客_bash 存在文件

Modular Programming

linux shell脚本中调用另一个shell脚本_whatday的专栏-CSDN博客_linux sh调用另一个sh

Interactive Input

User Input - Bash scripting Tutorial

Pasring Shell script Arguments

Internal Variables ==> official doc, all reserved variables ==> attention to "positional parameters"

https://www.baeldung.com/linux/use-command-line-arguments-in-bash-script

Quick Start Notes Variable
  • declare/initialize:
    • var_name = value
      • no explicit type declaration
      • all capitals by convention
        • lower case words and phrases are usually used for commands
    • var_name = $(some command)
      • take the result from some command and assign to var_name
  • refer: echo $var_name
    • echo var_name ==> print "var_name"
I/O
  • Interactive:
    • read var_name
  • get stdin:
    • /dev/stdin
    • use the file to get access to stdin; use with pipeline "|"
  • shell script calling arguments:
    •  see the positional parameters, usually $0 for the commands_interpretor/script_name, and $1+ for the arguments 
  • redirecting: Input Output Redirection in Linux/Unix Examples
    • >/< for output/input redirecting
      • >> for "append to destination" instead of overwritting as > would
script Tips 
  • get current running script location:
    • #!/bin/bash 
      # Absolute path to this script, e.g. /home/user/bin/foo.sh
      script=$(readlink -f "$0")
      # Absolute path this script is in, thus /home/user/bin
      scriptPATH=$(dirname "$script")
      echo $scriptPATH
  •  source vs. ./execute https://blog.csdn.net/maxzcl/article/details/122139734 
    • source operate within the current shell, while ./script will open a new sub_shell
    • !!!! the variables defined and modified (particularly those exported to system or modified systems variables) in script would only be available after termination when using "source" !!!!
    • and sometimes ./ is more portable, since its meaning is unmistakably simple. 
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/675506.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号