1. 程式人生 > 其它 >mac shell建立檔案/資料夾新增內容

mac shell建立檔案/資料夾新增內容

技術標籤:Shell指令碼

#!/bin/sh
# 獲取檔案所在位置
filePtth="$( cd "$( dirname "$0"  )" && pwd  )"
echo "當前檔案位置 $filePtth"
fireName="檔名"
allName="${filePtth}/${fireName}"
echo "完整路徑 $allName"
inputText="這裡還要寫入檔案的內容";
if [ -f "$allName" ]
then 
    echo "存在"
else
    echo "不存在"
    # 建立目錄在當前的位置
    # mkdir ${allName}

    # 建立檔案在當前的位置
    # touch ${allName}
    touch ${allName}
fi

if [ -f "$allName" ]
then 
    # 覆蓋內容
    # echo "$inputText" > "$allName"
    # 新增內容
    echo "$inputText" >> "$allName"
    echo "================================" >> "$allName"
fi