我想在bash腳本嵌入一個長的命令是這樣的:如何分解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
但是,這並不工作,因爲它打破了字符串文字。
有沒有辦法告訴bash打破字符串文字,但忽略任何前導空格?
好主意。你可以通過'+ ='運算符來代替'file = $ {file}/...' – Chriszuma
+1:在我看來,這是最少混淆的方法。意圖很明確。 –
@Chriszuma是的,我忘了bash允許'+ ='運算符。我編輯了我的答案。 – WilQu