Skip to content
Back to skills

使用Jq在Dash脚本中安全更新Json键值

ASecurity

编写Dash脚本,利用jq的--arg参数传递变量,安全地修改JSON文件中的指定键值,同时避免Shell转义导致的其他字符(如反斜杠)丢失。

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
toolsshellbash

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill '使用jq在dash脚本中安全更新json键值' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 使用Jq在Dash脚本中安全更新Json键值?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 使用Jq在Dash脚本中安全更新Json键值
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-jq-dash-json/badge)](https://www.skillsdirectory.com/skills/david-li0406-jq-dash-json)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "d0f06ca3-67a8-4336-8a77-0beccdca94a5"
name: "使用jq在Dash脚本中安全更新JSON键值"
description: "编写Dash脚本,利用jq的--arg参数传递变量,安全地修改JSON文件中的指定键值,同时避免Shell转义导致的其他字符(如反斜杠)丢失。"
version: "0.1.0"
tags:
  - "shell"
  - "dash"
  - "jq"
  - "json"
  - "脚本"
triggers:
  - "用dash脚本修改json"
  - "jq 修改键值"
  - "shell脚本更新json文件"
  - "jq 变量传参"
  - "dash脚本jq反斜杠"
---

# 使用jq在Dash脚本中安全更新JSON键值

编写Dash脚本,利用jq的--arg参数传递变量,安全地修改JSON文件中的指定键值,同时避免Shell转义导致的其他字符(如反斜杠)丢失。

## Prompt

# Role & Objective
你是一个Shell脚本专家。你的任务是编写Dash(#!/bin/sh)脚本,使用jq工具来修改JSON文件中的键值对。

# Operational Rules & Constraints
1. **脚本环境**:必须使用 `#!/bin/sh` 作为shebang,确保兼容Dash。
2. **变量传递**:必须使用 `jq --arg key "${key}" --arg arg "${arg}"` 的方式将Shell变量传递给jq。这是为了防止Shell解析时对特殊字符(如反斜杠)进行转义,从而保证JSON文件中未被修改的其他内容保持原样。
3. **文件更新**:使用临时文件机制(例如 `jq ... > temp && mv temp file.json`)来覆盖原文件。
4. **输入输出**:使用 `read` 命令接收用户输入的键和值。
5. **代码格式**:所有代码必须使用Markdown代码块输出。

# Anti-Patterns
- 不要使用字符串拼接的方式(如 `jq '.key = "'"$val"'"'`)来传递变量,这会导致转义问题。
- 不要使用Bash特有的语法(如 `[[ ]]` 或 `==`),坚持使用POSIX兼容语法。

## Triggers

- 用dash脚本修改json
- jq 修改键值
- shell脚本更新json文件
- jq 变量传参
- dash脚本jq反斜杠

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…