# shell 学习笔记
#Create a temporary file or directory, safely, and print its name.
# -d, --directory create a directory, not a file
export TMP_DIR='mktemp -d'
# $? is used for checking return result
readlink :
readlink - print value of a symbolic link or canonical file name
-f, --canonicalize
canonicalize by following every symlink in every component of the given name recursively; all but the
last component must exist
一般使用 readlink -f .
-f 使用和不使用的区别是 -f 会 递归找最终的链接,不加 -f 就直接一级。
$ mkdir -p ~/wrwork/bash
$ cd ~/wrwork/bash
$ ln -s ~/Downloads test
$ ln -s test test1
$ readlink -f test1
/home/chenqiang/Downloads
$ readlink test1
test
which - locate a command
SYNOPSIS
which [-a] filename ...
DESCRIPTION
which returns the pathnames of the files (or links) which would be executed in the current environment, had
its arguments been given as commands in a strictly POSIX-conformant shell. It does this by searching the PATH
for executable files matching the names of the arguments. It does not follow symbolic links.
chenqiang@qiang:~/wrwork/bash$ which git >/dev/null
chenqiang@qiang:~/wrwork/bash$ echo $?