TechBlog masa

  • Top
  • Posts
  • Profile
2025-01-24
SWE
Shell, Linux general notesShell, Linux general notes
Terminalshell

likes: 0

Unsupported Block: table_of_contents
zip -r {変換後名} {変換対象名}

-r : リカーシブに圧縮(ディレクトリを含むなら必須)
-e : パスワード付きで圧縮
-x : 特定のファイルやパターンを除外(eXclude). "*.tmp" "DS_Store" "*.cache"など。
-9 : 最高圧縮率で実行(デフォルトは-6)
ls -R
find . -type f -name "*.JPG" | while read file; do
  mv "$file" "${file%.JPG}.jpg"
done

カレントディレクトリ以下のすべての.JPGとつくファイルを.jpgに書き換え。

findで上がった対象をパイプでwhile…に渡す。

 

find . → カレントディレクトリ以下で、以下の条件で検索

-type f → ファイルのみ対象

-name → ファイル名/ディレクトリ名で検索

 

${file%.JPG}.jpg → fileでファイル名(read file; doによる)、file%.JPGでfileの末尾に一致する文字列を削除。

Unsupported Block: heading_2
find . -type f \( -name "*.JPG" -o -name "*.jpeg" \) | while read file; do
  mv "$file" "${file%.*}.jpg"
done

# readを以下のようにすると、ファイル名にスペースや特殊文字があっても安全に処理できる。
while IFS¥ read -r file

findには ”*.{JPG,jpeg}” のような書き方はできない。-oによってOR指定する。

exit 0 (exit) … 正常終了する。以降を実行しない

exit 0以外 … 異常終了する。以降を実行しない

これはどんな言語でもそう。

 

ただし、GitHub actionsのexit 0は、そのname内の処理のみを正常終了させる。exit 1は全て終了してくれるがFailedとして表示される。

actionsでは、正常終了かつ以降をスキップしたい場合、以下のように if: をそれぞれのname内に置くのが現在の打てる手。

if: env.continue_next !=”true”
run: ~~~
# バッシュスクリプト(shell script)はif-else-fiの最後のfiで閉じるのを忘れずに。
      - name: Check date # 日付をチェック
        id: date_check
        run: |
          current_date=$(date +'%m-%d')
          start_date="04-01"
          end_date="10-10"
          if [[ "$current_date" < "$start_date" || "$current_date" > "$end_date" ]]; then
            echo "Current date is out of the allowed range. Exiting."
            echo "continue_next_steps=false" >> $GITHUB_ENV
          else
            echo "Current date is within the allowed range."
            echo "continue_next_steps=true" >> $GITHUB_ENV
          fi  # ココ!!!
          
      # ちなみに、このブロックの if: は、actions独自の文法なので、シェルスクリプトのようなfiは不要。
      - name: Skip message if date is out of range
        if: env.continue_next_steps != 'true'
        run: echo "Skipped because current date is out of allowed range"
# 変数代入はスペース入れて"a = 100"としてはいけない。"a=100"とすること。
content="package main\n\n\nfunc main() {\n\n}" 

for i in {6..18}; do
    echo $content > "chap$i/main.go"
done
# カレントディレクトリに chap5,chap6...ディレクトリを作り、その中にさらにend-of-chapディレクトリ、a.pyファイルを作る。

for i in {5..18}; do
  mkdir -p "chap$i/end-of-chap"
  touch "chap$i/a.py"
done

# -pオプション:親ディレクトリ(ここではchap$i)が存在しない場合は一緒に作成する
breadcrumb予定地
profileCard予定地

SideBarPage

共有ボタン予定地
他ボタン予定地