定义

  1. #!/bin/bash
  2. alias ll="ls -al"

执行

内部 alias

开启 expand_aliases

  1. cat 3.sh
  2. #!/bin/bash
  3. shopt -s expand_aliases
  4. alias test7="ssh xx@xxxxx.com"
  5. test7
  6. ./3.sh
  7. Last login: Tue Nov 16 11:26:58 2021 from 192.168.88.101
  8. [bae@syt-dev7-d:~]$

外部 alias

方式一 source

  1. cat 3.sh
  2. #!/bin/bash
  3. shopt -s expand_aliases
  4. source ~/.bashrc
  5. test7
  6. ./3.sh
  7. Last login: Tue Nov 16 11:26:58 2021 from 192.168.88.101
  8. [bae@syt-dev7-d:~]$

方式二 bash -i

  1. cat 3.sh
  2. #!/bin/bash
  3. shopt -s expand_aliases
  4. test7
  5. ./3.sh
  6. ./3.sh: line 4: test7: command not found
  7. bash -i ./3.sh
  8. Last login: Tue Nov 16 11:26:46 2021 from 192.168.88.22
  9. [bae@syt-dev7-d:~]$

ssh command alias
ssh xx@xxx /bin/bash -ic ‘ll;lxgkp’