如何在bash中写入文件而不进行解析?

如何在bash中写入文件而不进行解析?,bash,echo,Bash,Echo,尝试在bash中编写以下命令时,使用/etc/languagetools/language_tool.sh中文件的可变路径: java -jar /path/to/languagetools/languagetool-commandline.jar "${@:1}" 我在阻止对“${@:1}”进行评估时遇到了一些困难。执行解析的函数包含: #!/bin/bash some_function() { local create_target_file=$(sudo touc

尝试在bash中编写以下命令时,使用
/etc/languagetools/language_tool.sh
中文件的可变路径:

java -jar /path/to/languagetools/languagetool-commandline.jar "${@:1}"
我在阻止对
“${@:1}”
进行评估时遇到了一些困难。执行解析的函数包含:

#!/bin/bash
some_function() {
  local create_target_file=$(sudo touch 
  $LANGUAGE_TOOL_TARGET_DIR/$LANGUAGE_TOOL_CONTROL_SCRIPTNAME)
  local make_readable=$(chmod 777 $LANGUAGE_TOOL_TARGET_DIR/$LANGUAGE_TOOL_CONTROL_SCRIPTNAME)
  command_one="java -jar 
  $LANGUAGE_TOOL_TARGET_DIR/$LANGUAGE_TOOL_SNAPSHOT_DIRNAME/$LANGUAGE_TOOL_TARGET_FILENAME "
  command_two='${@:1}'
  local write_content_to_file=$(sudo sh -c "echo $command_one$command_two > $LANGUAGE_TOOL_TARGET_DIR/$LANGUAGE_TOOL_CONTROL_SCRIPTNAME")
}
返回:

sh:1:换人不好


因此,我很好奇,如何在不解析命令内容的情况下将命令字符串写入文件?

您不需要命令替换或变量赋值。只是

echo "$command_one$command_two" > "$LANGUAGE_TOOL_TARGET_DIR/$LANGUAGE_TOOL_CONTROL_SCRIPTNAME"

检查您是否正在使用bash或sh。“${@:1}”是bash扩展。是的,我在示例代码中包括了bash shebang。