I am trying to write a shell script, and get the input parameters, like:
./test abc def ghi
If there is a echo $*
inside the script, it would list down the parameters, however quotation marks disappear, like
./test abc "def ghi"
--> abc def ghi
I dont want to run the command with back-slash as ./test abc \\"def ghi\\"
, although it could solve this problem. echo $2
would not solve the quotation inside it, like ./test abc "def ghi "jkl" mno"
Is there any other way to solve it? Thank you:)
You can do it by wrapping the double-quotes inside single quotes, like so:
./test abc '"def ghi"'
Explanation:
Everything enclosed by single-quotes is interpreted as string literals by shell. Here's some more information on Strong Quoting vs. Weak Quoting .
您也可以使用单引号:
./test abc '"def ghi"'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.