Linux Bash Tutorial

15 篇文章 0 订阅

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

Remote Manipulation

使用linux 的shell脚本进行sftp文件上传与下载(转)_EverNoob的博客-CSDN博客_linux的sftp脚本

Linux sftp命令_书香水墨的博客-CSDN博客_linux sftp 

SSH: Execute Remote Command or Script - Linux - ShellHacks 

Special Characters

1. for most POSIX strings, simply use escape

2. for embedded passwd, (e.g. for git pull), use URL or 'percent encoding': GIT: Calling git clone using password with special character | Fabian Lee : Software Engineer

!   #   $    &   '   (   )   *   +   ,   /   :   ;   =   ?   @   [   ]
%21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D

 

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"
  • value substitution: ${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. 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值