我正在尝试检查Bash脚本中是否存在命令。我使用Bash内置命令type -t
,除了别名外,它运行良好。
这是一个例子:
#! /bin/bash
echo "> Defining alias lll.."
alias lll='ls'
echo "> Testing type of lll.."
type -t lll
echo "> Return code form type -t: $?"
echo "> Checking that alias lll is really defined.."
alias lll
echo "> Testing type -t for ordinary command 'ls' ( not alias )"
type -t ls
输出结果为:
> Defining alias lll..
> Testing type of lll..
> Return code form type -t: 1
> Checking that alias lll is really defined..
alias lll='ls'
> Testing type -t for ordinary command 'ls' ( not alias )
file
为什么type -t lll
会给出返回代码1(未找到)?当我从终端窗口运行此命令时,它运行良好(返回代码为0),因此问题似乎特定于脚本设置..