顯示具有 [Linux] shell 標籤的文章。 顯示所有文章
顯示具有 [Linux] shell 標籤的文章。 顯示所有文章

2023年9月6日 星期三

[Linux] shell script - 特殊符號 $0、$1、$2、$#、$@、$*、$? 的含義

 在编写 Linux bash shell 脚本时,经常会用到 $0、$1、$2、$#、$@、$*、$? 等参数。下面具体说明这些参数的含义。

假设执行 ./test.sh a b c 这样一个命令,则可以使用下面的参数来获取一些值:

2022年3月8日 星期二

【Linux】Shell Script 檢查檔案、目錄是否存在

檢查目錄是否存在


#!/bin/sh



if [ -d "/path/to/dir" ]; then

# 目錄 /path/to/dir 存在

echo "Directory /path/to/dir exists."

else

# 目錄 /path/to/dir 不存在

echo "Directory /path/to/dir does not exists."

fi