我想在bash脚本中嵌入这样的长命令:

mycommand \
    --server myserver \
    --filename extremely/long/file/name/that/i/would/like/to/be/able/to/break/up/if/possible \
    --otherflag \
    --anotherflag

随着漫长的分手.

我可以这样做:

# Insufficiently pretty
mycommand \
    --server myserver \
    --filename extremely/long/file/name/\
that/i/would/like/to/be/able/to/break/\
up/if/possible \
    --otherflag \
    --anotherflag \

但它打破了流程.我希望我能写下:

# Doesn't work
mycommand \
    --server myserver \
    --filename extremely/long/file/name/\
         that/i/would/like/to/be/able/to/break/\
         up/if/possible \
    --otherflag \
    --anotherflag

但这不起作用,因为它 destruct 了字符串文字.

有没有一种方法可以告诉bash打断字符串文字,但忽略任何前导空格?

推荐答案

您可以使用一个变量:

file=extremely/long/file/name
file+=/that/i/would/like/to/be/able/to/break
file+=/up/if/possible

mycommand\
    --server myserver\
    --filename $file\
    --flag flag

Linux相关问答推荐

我使用Windows 10,但我无法在我的WSL2上下载vscode

在Linix&;Mac中运行Reaction本机项目时出现问题

为什么waitpid(2)可以指定非子进程?

bind() 错误 98 - 地址已在使用中

命令行中使用`..`为什么会导致权限被拒绝错误?

8 个半小时范围的 Crontab 表达式

Bash shift 改变了关联数组的期望值

在 Windows 上通过 SSH 运行 django 应用程序

sed 命令在 gitlab runner 上无法正确执行

使用 bash 中的数字对 RPM 内核字符串进行版本排序返回不正确的结果

Linux合并文件

用于 GCC/G++ 的宏来区分 Linux 和 Mac OSX?

在 Ubuntu 中重启 Nginx

加密/解密在两个不同的 openssl 版本之间不能很好地工作

用于数据库备份的 Linux shell 脚本

Linux AMD64 中如何使用 fs/gs 寄存器?

在 Linux 上用 C 语言读写串口

如何在 Linux 上查找不包含文本的文本文件?

conda 命令会提示错误:Bad Interpreter: No such file or directory

通过 linux x86-64 函数调用保留了哪些寄存器