#!/bin/bash # testfunc.bash, 注意后缀是bash,而不是sh,因为`[[`判断符与sh不兼容 echo"Starting program at $(date)"# date会被替换成日期和时间 # `$$`进程ID,`$#`参数个数,$0当前命令 echo"Running program $0 with $# arguments with pid $$" # `$@`所有参数 for file in$@; do grep foobar $file > /dev/null 2> /dev/null # 如果模式没有找到,则grep退出状态为 1 # 我们将标准输出流和标准错误流重定向到Null,因为我们并不关心这些信息 if [[ $? -ne 0 ]]; then echo"File $file does not have any foobar, adding one" echo"# foobar" >> "$file" fi done # `source testfunc.bash` # 输出: # Starting program at 2020年12月20日 星期日 14时52分03秒 CST # Running program ./testfunc.bash with 0 arguments with pid 10741 # 加点参数执行 `source testfunc.bash test1 test2`, 同时在同级目录下生成了 test1 & test2文件并向文件中输入了 `# foobar` Starting program at 2020年12月20日 星期日 14时54分51秒 CST Running program ./testfunc.bash with 2 arguments with pid 10741 File test1 does not have any foobar, adding one File test2 does not have any foobar, adding one
# 打开命令行 # 查看现有的ssh keys ls -al ~/.ssh # 如果有以下文件中的一个,则代表待会创建的就是第二份的 ssh publick id_rsa id_rsa.pub id_ecdsa.pub id_ed25519.pub # Generating a new ssh key by your_email@example.com ssh-keygen -t rsa -b 4096 -C "your_email@example.com" # 命令行提示 > Generating public/private rsa key pair. # 不要直接回车,否则会覆盖已有的,重新键入: 比如文件名这里改成了 id_dubble_rsa,记住这个文件名! > Enter a file inwhich to save the key (/Users/you/.ssh/id_rsa): /Users/you/.ssh/id_dubble_rsa # 接下来按照提示键入 > Enter passphrase (empty for no passphrase): [Type a passphrase] > Enter same passphrase again: [Type passphrase again]
将新的ssh key添加到 ssh-agent
1 2 3 4 5 6 7
eval"$(ssh-agent -s)" > Agent pid 59566 # 如果你是 mac 用户,还需要修改 ~/.ssh/config文件 open ~/.ssh/config # 如果没有这个config文件,则手动生成一个 touch ~/.ssh/config # 记事本会打开这个文件