小编Fra*_*a ت的帖子

如何在 Bash 参数中保留空格

我使用命令:

cm1 cm2 arg1 arg2 'argument 3'
Run Code Online (Sandbox Code Playgroud)

它首先转到cm1,然后重定向arg1 arg2 'argument 3'到另一个文件。

/usr/bin/cm1

#! /bin/bash
# some script here
shift
cm2 $@
Run Code Online (Sandbox Code Playgroud)

/usr/bin/cm2

echo $#
# This returns 4 in lieu of 3 because the white space in 'argument 3' causes the argument to be split into two arguments.
Run Code Online (Sandbox Code Playgroud)

那么,如何将参数从一个脚本传递到另一个脚本并确保不会将空格作为参数分隔符读取?

unix bash arguments command-line-arguments

7
推荐指数
1
解决办法
8109
查看次数

标签 统计

arguments ×1

bash ×1

command-line-arguments ×1

unix ×1