如何将反斜杠参数传递给脚本?

编程入门 行业动态 更新时间:2024-10-28 01:25:08
本文介绍了如何将反斜杠参数传递给脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我只想在文本文件中附加一个用户输入参数.我正在使用以下命令:

I just want to append an user input argument in a text file. I'm using the following command:

echo "$2" >> "./db.txt"

希望用户

$ 2 设置路径,例如: D:\ Projects \ MyProject .它写入文件,但没有反斜杠.结果是:

$2 is expected to user to set a path like: D:\Projects\MyProject. It writes to the file, but with no backslashes. The result is:

D:ProjectsMyProject

D:ProjectsMyProject

我在任何地方都找不到解决方法.我尝试使用 -e 或 -E 参数(从这里获取),但在这种情况下似乎没有什么区别.

I can't find anywhere how to fix that. I've tried using -e or -E params(taken from here) but it doesn't seems to make difference in this case.

推荐答案

您必须在shell中转义反斜杠: \\ ,或将字符串放在引号中.

You have to escape backslashes in the shell: \\, or put the string in quotes.

出于调试目的,请使用 set -x .

For debugging purposes use set -x.

更多推荐

如何将反斜杠参数传递给脚本?

本文发布于:2023-06-04 19:06:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/503300.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:斜杠   如何将   脚本   参数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!